C语言 isdigit() 函数—测试字符是否为阿拉伯数字

转自:http://see.xidian.edu.cn/cpp/html/116.html

相关函数 isxdigit
头文件 #include <ctype.h>
定义函数 int isdigit(int c);
函数说明检查参数 c 是否为阿拉伯数字0 到9.
返回值若参数c 为阿拉伯数字, 则返回TRUE, 否则返回NULL(0).
附加说明此为宏定义, 非真正函数.
范例 /* 找出str 字符串中为阿拉伯数字的字符 */
#include <ctype.h>
main()
{
char str[] = "123@#FDsP[e?";
int i;
for(i = 0; str[i] != 0; i++)
if(isdigit(str[i]))
printf("%c is an digit character\n", str[i]);
}
执行 1 is an digit character
2 is an digit character
3 is an digit character 

posted @ 2012-03-02 14:31  学习从博客园开始  Views(965)  Comments(0)    收藏  举报