用来检测一个字符是否是十进制数字
十进制数字包括:0 1 2 3 4 5 6 7 8 9
1,头文件:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
2,参数
要检测的字符。它可以是一个有效的字符(被转换为 int 类型),也可以是 EOF(表示无效的字符)。
3,返回值
返回值为非零(真)表示c是十进制数字,返回值为零(假)表示c不是十进制数字
事例:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char str[]="1776ad";
int year;
if (isdigit(str[0]))
{
year = atoi (str);
printf ("The year that followed %d was %d.\n", year, year+1);
}
return 0;
}
运行结果: