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 209 views
1 answer 187 views
1 answer 116 views
3 answers 191 views
3 answers 138 views
1 answer 126 views
...