C examples for ctype.h:isdigit
function
<cctype> <ctype.h>
Check if character is decimal digit. Decimal digits are any of: 0 1 2 3 4 5 6 7 8 9.
int isdigit ( int c );
Parameter | Description |
---|---|
c | Character to be checked, casted to an int, or EOF. |
A non zero value (i.e., true) if indeed c is a decimal digit. Zero (i.e., false) otherwise.
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main ()/*from ww w .jav a 2s . c om*/ { char str[]="this is a test 1776 test"; int year; if (isdigit(str[0])) { year = atoi (str); printf ("The year that followed %d was %d.\n",year,year+1); } return 0; }