字符测试函数:C语言isxdigit()函数----判断字符是否为16进制数字

来源:互联网 发布:mysql数据库文件扩展名 编辑:程序博客网 时间:2024/05/16 19:52
头文件:#include <ctype.h>

定义函数:int isxdigit (int c);

函数说明:检查参数c是否为16 进制数字,只要c为下列其中一个情况就检测成功。

16进制数字:0123456789ABCDEF。

返回值:若参数c 为16 进制数字,则返回非 0,否则返回 0。

附加说明:此为宏定义,非真正函数。

范例:找出字符串str 中为十六进制数字的字符。

#include <ctype.h>main(){    char str[] = "123c@#FDsP[e?";    int i;    for(i = 0; str[i] != 0; i++)        if(isxdigit(str[i]))            printf("%c is a hexadecimal digits\n", str[i]);}

执行结果:
1 is a hexadecimal digits
2 is a hexadecimal digits
3 is a hexadecimal digits
c is a hexadecimal digits
F is a hexadecimal digits
D is a hexadecimal digits
e is a hexadecimal digits

0 0