曲径通幽论坛

标题: isxdigit() -- 测试十六进制数字 [打印本页]

作者: beyes    时间: 2011-12-17 13:51
标题: isxdigit() -- 测试十六进制数字
isxdigit() 函数原型如下:
[C++] 纯文本查看 复制代码
#include <ctype.h>
int isxdigit(int c);[/quote]
该函数检查其参数 c 是否为十六进制数字,这里的十六进制数字包括:0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c ,d ,e, f, A, B, C, D, E, F 。只要 c 是其中之一,那么函数返回 TRUE ,否则返回 NULL 。

测试代码
[mw_shl_code=cpp,true]#include <stdio.h>
#include <ctype.h>

int main()
{
        char str[] = "123@#$abc*&^DEF";
        int i;

        for (i = 0; str != 0; i++)
                if (isxdigit(str))
                        printf ("%c is a hexadcimal digits.\n", str);

        return 0;
}

运行输出:
./isxdigit
1 is a hexadcimal digits.
2 is a hexadcimal digits.
3 is a hexadcimal digits.
a is a hexadcimal digits.
b is a hexadcimal digits.
c is a hexadcimal digits.
D is a hexadcimal digits.
E is a hexadcimal digits.
F is a hexadcimal digits.





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2