C ctype isdigit() 函数
示例
检查一个字符是否是数字
char c = '8';
if (isdigit(c)) {
printf("%c is a digit", c);
} else {
printf("%c is not a digit", c);
}
自己动手试一试 »
定义和用法
如果字符是数字,则 isdigit()
函数返回一个非零值(等同于布尔值 true)。
isdigit()
函数定义在 <ctype.h>
头文件中。
语法
int isdigit(int c);
参数值
参数 | 描述 |
---|---|
c | 必需。字符的 ASCII 值或实际字符 |
技术详情
返回 | 如果该字符是十进制数字,则返回一个非零的 int 值(等同于布尔值 true)。否则返回 0(等同于布尔值 false)。 |
---|