How to check if string is a positive 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

2 answers 335 views
1 answer 271 views
1 answer 189 views
3 answers 321 views
3 answers 281 views
1 answer 214 views
...