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 297 views
1 answer 273 views
1 answer 193 views
2 answers 236 views
1 answer 204 views
1 answer 190 views
...