使用使用C语言判断英文字符大小写的方法语言判断英文字符大小写的方法
C语言语言isupper()函数:判断字符是否为大写英文字母函数:判断字符是否为大写英文字母
头文件:
#include <ctype.h>
定义函数:
int isupper(int c);
函数说明:检查参数c是否为大写英文字母。
返回值:若参数c 为大写英文字母,则返回非 0,否则返回 0。
附加说明:此为宏定义,非真正函数。
范例:找出字符串str 中为大写英文字母的字符。
#include <ctype.h>
main(){
char str[] = "123c@#FDsP[e?";
int i;
for(i = 0; str[i] != 0; i++)
if(isupper(str[i]))
printf("%c is an uppercase character", str[i]);
}
执行结果:
F is an uppercase character
D is an uppercase character
P is an uppercase character
C语言语言islower()函数:判断字符是否为小写字母函数:判断字符是否为小写字母
头文件:
#include <ctype.h>
islower() 用来判断一个字符是否是小写字母,其原型为:
int islower(int c);
【参数】c 为需要检测的字符。
【返回值】若参数c 为小写英文字母,则返回非 0 值,否则返回 0。
注意,此为宏定义,非真正函数。
【实例】判断str 字符串中哪些为小写字母。
#include <ctype.h>
main(){
char str[] = "123@#FDsP[e?";
int i;
for(i = 0; str[i] != 0; i++)
if(islower(str[i]))
printf("%c is a lower-case character", str[i]);
}
输出结果:
c is a lower-case character
s is a lower-case character
e is a lower-case character
您可能感兴趣的文章您可能感兴趣的文章:C++统计中英文大小写字母、数字、空格及其他字符个数的方法C语言中对字母进行大小写转换的简单方
法C语言实现字母大小写转换的方法C语言中利用封装好的函数实现英文字母的大小写转换C++实现高性能转换大小写算法示
评论10