How to check if string is a negative integer in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char str[8] = "-5";

    int n = atoi(str);

    printf("%s", (n < 0) ? "yes" : "no");

    return 0;
}





/*
run:

yes

*/

 



answered Jun 25, 2022 by avibootz

Related questions

1 answer 304 views
1 answer 279 views
1 answer 201 views
2 answers 241 views
1 answer 211 views
1 answer 198 views
...