How to check if a string contains a number in C

1 Answer

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

int digits_only(const char* s) {
    while (*s) {
        if (*s >= '0' || *s <= '9') return 1;
        s++;
    }

    return 0;
}

int main(void) {
    char s[] = "F-15 Eagle";

    printf("%s", digits_only(s) ? "yes" : "no");

    return 0;
}




/*
run:

yes

*/

 



answered Jul 29, 2022 by avibootz
...