C语言中isalnum()函数和isalpha()函数的对比使用

更新时间:2023-05-19 06:25:18 阅读: 评论:0

C语⾔中isalnum()函数和isalpha()函数的对⽐使⽤C语⾔isalnum()函数:判断字符是否为英⽂字母或数字
头⽂件:
#include <ctype.h>
isalnum() ⽤来判断⼀个字符是否为英⽂字母或数字,相当于 isalpha(c) || isdigit(c),其原型为:
int isalnum(int c);
【参数】c 为需要检测的字符。
【返回值】若参数c 为字母或数字,若 c 为 0 ~ 9  a ~ z  A ~ Z 则返回⾮ 0,否则返回 0。
注意,isalnum()为宏定义,⾮真正函数。
【实例】找出str 字符串中为英⽂字母或数字的字符。
#include <ctype.h>
main(){
狂拽酷炫吊炸天
char str[] = "123c@#FDsP[e?";
int i;
热狗英语for (i = 0; str[i] != 0; i++)
if(isalnum(str[i]))
printf("%c is an alphanumeric character\n", str[i]);
}
小学生开学
输出结果:
1 is an apphabetic character
2 is an apphabetic character
3 is an apphabetic character
c is an apphabetic character
F is an apphabetic character
D is an apphabetic character
s is an apphabetic character
P is an apphabetic character
e is an apphabetic character
C语⾔isalpha()函数:判断字符是否为英⽂字母
头⽂件:
#include <ctype.h>
isalpha() ⽤来判断⼀个字符是否是英⽂字母,相当于 isupper(c)||islower(c),其原型为:
五香果
int isalpha(int c);
【参数】c 为需要被检测的字符。
【返回值】若参数c 为英⽂字母(a ~ z  A ~ Z),则返回⾮ 0 值,否则返回 0。
注意,isalpha() 为宏定义,⾮真正函数。
【实例】找出str 字符串中为英⽂字母的字符。
#include <ctype.h>
main(){
deorechar str[] = "123c@#FDsP[e?";
int i;
for (i = 0; str[i] != 0; i++)
if(isalpha(str[i]))
printf("%c is an alphanumeric character\n", str[i]);
}
杰克道森
执⾏结果:
c is an apphabetic character
日记40字>扇枕温衾的故事F is an apphabetic character
D is an apphabetic character
s is an apphabetic character
P is an apphabetic character e is an apphabetic character

本文发布于:2023-05-19 06:25:18,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/915926.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:字母   字符   是否   找出   判断   函数   炸天
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图