C <ctype.h> - isdigit() Function
The C <ctype.h> isdigit() function is used to check if the given character is a decimal digit or not. Decimal digits are one of the 10 digits: 0123456789.
Syntax
int isdigit ( int ch );
Parameters
ch |
Specify the character to be checked, casted to an int, or EOF. |
Return Value
Returns non-zero value (i.e, true) if ch is a decimal digit, else returns zero (i.e, false).
Example:
The example below shows the usage of isdigit() function.
#include <stdio.h> #include <ctype.h> int main (){ char str[50] = "980Alpha55"; //counting the numbers of //decimal digits in str int i = 0, count = 0; while(str[i]) { if(isdigit(str[i])) count++; i++; } //displaying the output printf("%s contains %d decimal digits.", str, count); return 0; }
The output of the above code will be:
980Alpha55 contains 5 decimal digits.
❮ C <ctype.h> Library