C语言islower()函数:判断字符是否为小写字母
islower()函数
头文件和函数原型
#include <ctype.h>
int islower(int c);
描述
islower()
是C语言标准库中的一个函数,用于检查一个字符是否为小写字符(字符a-z,对应的ASCII码是97~122);
返回值
如果传入的字符参数是小写字母,则返回非0
值,否则返回0
;
示例代码
该示例指出字符串中不属于小写字母的字符;
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char str[] = "abcdEfghijKlmn0123.xyz";
size_t length = strlen(str);
printf("%s\n", str);
for (int i = 0; i < length; i++) {
printf("%c", islower(str[i]) ? ' ' : '^');
}
printf("\n");
}
程序运行效果
abcdEfghijKlmn0123.xyz ^ ^ ^^^^^