C语言isalpha()函数:判断一个字符是否是字母
C语言 isalpha() 函数用来检测一个字符是否是字母,包括大写字母和小写字母。
头文件:ctype.h
语法/原型:
返回值:返回非 0(真)表示 c 是字母,返回 0(假)表示 c 不是字母。
【实例】C语言 isalpha() 函数判断一个字符串中的字符是否是字母。
C is alphabetic
+ is not alphabetic
+ is not alphabetic
is not alphabetic
J is alphabetic
a is alphabetic
v is alphabetic
a is alphabetic
is not alphabetic
C is alphabetic
# is not alphabetic
头文件:ctype.h
语法/原型:
int isalpha(int c);
参数 c 表示要检测字符或者 ASCII 码。返回值:返回非 0(真)表示 c 是字母,返回 0(假)表示 c 不是字母。
【实例】C语言 isalpha() 函数判断一个字符串中的字符是否是字母。
#include <stdio.h> #include <ctype.h> int main() { int i = 0; char str[] = "C++ Java C#"; while (str[i]) { if (isalpha(str[i])) { printf("%c is alphabetic\n", str[i]); } else { printf("%c is not alphabetic\n", str[i]); } i++; } return 0; }运行结果:
C is alphabetic
+ is not alphabetic
+ is not alphabetic
is not alphabetic
J is alphabetic
a is alphabetic
v is alphabetic
a is alphabetic
is not alphabetic
C is alphabetic
# is not alphabetic