Determines if a character is a digit (0?9).
int isdigit ( int c );
This function has the following parameter.
A value different from zero (i.e., true) if indeed c is a decimal digit. Zero (i.e., false) otherwise.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
//from w w w . j av a2 s.c o m
int main (){
char str[]="123123ad";
int year;
if (isdigit(str[0]))
{
year = atoi (str);
printf ("The year that followed %d was %d.\n",year,year+1);
}
return 0;
}
The code above generates the following result.
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
/*from w ww .j ava2 s . c o m*/
int main(void)
{
for (int ndx=0; ndx<=UCHAR_MAX; ndx++)
if (isdigit(ndx)) printf("%c", ndx);
printf("\n");
}
The code above generates the following result.