曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 3534|回复: 0
打印 上一主题 下一主题

[字符串] isxdigit() -- 测试十六进制数字

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2011-12-17 13:51:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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 。

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

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

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

        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.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-3 23:15 , Processed in 0.080119 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表