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 301 views
1 answer 277 views
1 answer 195 views
2 answers 238 views
1 answer 206 views
1 answer 192 views
...