一种函数:判断字符ch是否为英文字母,若为小写字母,返回2,若为大写字母,返回1。若不是字母,返回0。在标准c中相当于使用“isupper(ch)||islower(ch)”做测试,
头文件加入或者 (C语言使用)
isupper
原型:extern int
isupper(int c);
头文件:(旧版本的编译器使用<
ctype.h>)
功能:判断
字符c是否为大写英文字母
说明:当参数c为大写英文字母(A-Z)时,返回非零值,否则返回零。
附加说明: 此为
宏定义,非真正函数。
islower
islower(测试
字符是否为小写字母)
相关函数
isalpha,
isupper
表头文件
#include(旧版本的编译器使用<
ctype.h>)
定义函数
int islower(int c)
函数说明
检查参数c是否为小写英文字母。
返回值
若参数c为小写英文字母,则返回TRUE,否则返回NULL(0)。
附加说明:此为
宏定义,非真正函数。
}
#include
#include
int main(void)
{
char ch;
int total;
total=0;//赋值
/*统计字母块*/
do
{
ch=getchar();
if(isalpha(ch)!=0)
++total;
}while(ch!='.');//结束符号为.
printf("The total of letters is:%dn",total);
return 0;
}
/*运行结果*/
输入:123456我am精明的画板.
输出:The total of letters is:2
尤其在输入一大段包括字母和数字的情况下用这个函数很方便
转载于百度百科