大宇私人领地伊甸园丨宁愿做了后悔,也不要错过后悔[www.mrdayu.com]
注册

24小时联系邮箱:[email protected]

所有文章
大宇私人伊甸园: 首页 > 所有文章 > 编程人生 > C/C++语言 > C标准库详解 > isxdigit()函数详解


友情链接:


isxdigit()函数详解

发布时间:2018/11/22 C标准库详解 标签isxdigit阅读:45

函数原形:

extern int isxdigit(int c);

头文件包含:

#include <ctype.h>

功能:

判断字符c是否为十六进制数字

说明:

当c为A-F,a-f或0-9之间的十六进制数字时,返回非零值,否则返回零。

官方测试函数功能代码:

#include <stdio.h>
#include <ctype.h>

int main(){
        int c;
        c='a';
        printf("%c:%s\n",c,isxdigit(c)?"yes":"no");
        c='9';
        printf("%c:%s\n",c,isxdigit(c)?"yes":"no");
        c='*';
        printf("%c:%s\n",c,isxdigit(c)?"yes":"no");
        return 0;
}

运行效果:

[[email protected] STDC]$ gcc stdc_isxdigit.c 
[[email protected] STDC]$ ./a.out 
a:yes
9:yes
*:no

Linux平台运行测试:

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
/*int main(){
  int c;
  c='a';
  printf("%c:%s\n",c,isxdigit(c)?"yes":"no");
  c='9';
  printf("%c:%s\n",c,isxdigit(c)?"yes":"no");
  c='*';
  printf("%c:%s\n",c,isxdigit(c)?"yes":"no");
  return 0;
  }*/
int main(){
        char str[] = "[email protected]#FDsP[e?456789A";
        int i;
        for(i = 0; str[i] != 0; i++){
                if(isxdigit(str[i])){
                        printf("%c is an digit character\n", str[i]);
                }
        }
        return 0;
}

运行结果:

[[email protected] STDC]$ gcc stdc_isxdigit.c
[[email protected] STDC]$ ./a.out 
1 is an digit character
2 is an digit character
a is an digit character
d is an digit character
f is an digit character
d is an digit character
d is an digit character
a is an digit character
3 is an digit character
F is an digit character
D is an digit character
e is an digit character
4 is an digit character
5 is an digit character
6 is an digit character
7 is an digit character
8 is an digit character
9 is an digit character
A is an digit character

提醒:千万记得是isxdigit()不是isdigit()。

Windows平台测试:

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
int main(){
	char str[] = "[email protected]#FDsP[e?456789A";
	int i;
	for (i = 0; str[i] != 0; i++){
		if (isxdigit(str[i])){
			printf("%c is an digit character\n", str[i]);
		}
	}
	getchar();
	return 0;
}

运行结果:

1 is an digit character
2 is an digit character
a is an digit character
d is an digit character
f is an digit character
d is an digit character
d is an digit character
a is an digit character
3 is an digit character
F is an digit character
D is an digit character
e is an digit character
4 is an digit character
5 is an digit character
6 is an digit character
7 is an digit character
8 is an digit character
9 is an digit character
A is an digit character
The bottom line, for me, is simple.

Let’s hope it doesn’t take 500 years for a discipline of testing to becomes the standard for software developers.

From:dayu

您好!请登录

合作网站快捷登录:
点击取消回复

已有0评论

    大宇博客

    点击这里给我发消息 点击这里给我发消息 点击这里给我发消息 点击这里给我发消息