栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言中isdigit()函数和isxdigit()函数的用法

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言中isdigit()函数和isxdigit()函数的用法

C语言isdigit()函数:判断字符是否为阿拉伯数字
头文件:

#include 

定义函数:

int isdigit(int c);

函数说明:检查参数 c 是否为阿拉伯数字0 到9。

返回值:若参数c 为阿拉伯数字,则返回true,否则返回null(0)。

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

范例:找出str 字符串中为阿拉伯数字的字符。

#include 
main(){
 char str[] = "123@#FDsP[e?";
 int i;
 for(i = 0; str[i] != 0; i++)
  if(isdigit(str[i]))
   printf("%c is an digit charactern", str[i]);
}

执行结果:

1 is an digit character
2 is an digit character
3 is an digit character

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

头文件:

#include 

定义函数:

int isxdigit (int c);

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

16进制数字:0123456789ABCDEF。

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

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

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

#include 
main(){
 char str[] = "123c@#FDsP[e?";
 int i;
 for(i = 0; str[i] != 0; i++)
  if(isxdigit(str[i]))
   printf("%c is a hexadecimal digitsn", 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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/64962.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号