How to check if a string contain a multiple digit in C

1 Answer

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

int contain_multiple_digit(char* s) {
    int count = 0;;

    while (*s) {
        if (isdigit(*s)) {
            count++;
        }
        s++;
    }
    
    return count >= 2;
}

int main(void)
{
    char str[] = "C 17 is a general purpose computer 287 programming language";

    if (contain_multiple_digit(str)) {
        puts("yes");
    }
    else {
        puts("no");
    }

    return 0;
}




/*
run:

yes

*/

 



answered Dec 11, 2023 by avibootz

Related questions

...