C语言isalpha()函数:判断字符是否为英文字母
头文件:#include <ctype.h>
isalpha() 用来判断一个字符是否是英文字母,相当于 isupper(c)||islower(c),其原型为:
int isalpha(int c);
【参数】c 为需要被检测的字符。
【返回值】若参数c 为英文字母(a ~ z A ~ Z),则返回非 0 值,否则返回 0。
注意,isalpha() 为宏定义,非真正函数。
【实例】找出str 字符串中为英文字母的字符。
执行结果:
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
isalpha() 用来判断一个字符是否是英文字母,相当于 isupper(c)||islower(c),其原型为:
int isalpha(int c);
【参数】c 为需要被检测的字符。
【返回值】若参数c 为英文字母(a ~ z A ~ Z),则返回非 0 值,否则返回 0。
注意,isalpha() 为宏定义,非真正函数。
【实例】找出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]); }
执行结果:
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