c语言中函数isalpha,isalpha C语言中isalnum()函数和isalpha()函数的对比

C语言isalnum()函数:判断字符是否为英文字母或数字

头文件:

#include

isalnum() 用来判断一个字符是否为英文字母或数字,相当于 isalpha(c) || isdigit(c),其原型为:

int isalnum(int c);

【参数】c 为需要检测的字符。

【返回值】若参数c 为字母或数字,若 c 为 0 ~ 9 a ~ z A ~ Z 则返回非 0,否则返回 0。

注意,isalnum()为宏定义,非真正函数。

【实例】找出str 字符串中为英文字母或数字的字符。

#includemain(){ char str[] = "123c@#FDsP[e"; int i; for (i = 0; str[i] != 0; i++) if(isalnum(str[i])) printf("%c is an alphanumeric charactern", str[i]);}

输出结果:

1 is an apphabetic character2 is an apphabetic character3 is an apphabetic characterc is an apphabetic characterF is an apphabetic characterD is an apphabetic characters is an apphabetic characterP is an apphabetic charactere is an apphabetic character

C语言isalpha()函数:判断字符是否为英文字母

头文件:

#include

isalpha() 用来判断一个字符是否是英文字母,相当于 isupper(c)||islower(c),其原型为:

int isalpha(int c);

【参数】c 为需要被检测的字符。

【返回值】若参数c 为英文字母(a ~ z A ~ Z),则返回非 0 值,否则返回 0。

注意,isalpha() 为宏定义,非真正函数。

【实例】找出str 字符串中为英文字母的字符。

#includemain(){ char str[] = "123c@#FDsP[e"; int i; for (i = 0; str[i] != 0; i++) if(isalpha(str[i])) printf("%c is an alphanumeric charactern", str[i]);}

执行结果:

c is an apphabetic characterF is an apphabetic characterD is an apphabetic characters is an apphabetic characterP is an apphabetic charactere is an apphabetic character

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值