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。against all odds
注意,isalnum()为宏定义,⾮真正函数。
【实例】找出str 字符串中为英⽂字母或数字的字符。
#include <ctype.h>
main(){
char str[] = "123c@#FDsP[e?";
int i;
vancl是什么意思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
pk英语
e is an apphabetic character
C语⾔isalpha()函数:判断字符是否为英⽂字母
头⽂件:
#include <ctype.h>
isalpha() ⽤来判断⼀个字符是否是英⽂字母,相当于 isupper(c)||islower(c),其原型为:
int isalpha(int c);
【参数】c 为需要被检测的字符。
scotty mccreery
【返回值】若参数c 为英⽂字母(a ~ z A ~ Z),则返回⾮ 0 值,否则返回 0。
注意,isalpha() 为宏定义,⾮真正函数。
une【实例】找出str 字符串中为英⽂字母的字符。
#include <ctype.h>
main(){
算分器char 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]);
}
albeit
执⾏结果:
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