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

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

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

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 字符串中为英文字母或数字的字符。

#include 
main(){
  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 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 

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

  int isalpha(int c);

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

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

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

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

#include 
main(){
  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 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

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

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

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