当前位置: C语言 -- 标准库 -- <ctype.h> -- islower

islower函数


概要:
#include <ctype.h>
int islower(int c);

描述:

该函数用于检查字符是否为小写字母。

该函数行为会受当前语言环境影响。默认环境中(即“C”语言环境),小写字母为下述成员之一:

a b c d e f g h i j k l m n o p q r s t u v w x y z

非默认环境中,小写字母还包括特定语言环境字符集成员,该成员的iscntrlisdigitispunctisspace函数返回值均为false


参数:
int c

参数c为一个int类型整数,其值可用unsigned char类型表示或者等于宏EOF。如果参数c是其它值,函数行为是未定义的。


返回值:

如果参数c是小写字母,函数返回非0值(即true);反之,如果参数c不是小写字母,函数返回0(即false)。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
/*函数islower范例*/

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    int i = 0;
    int count = 0;    //计数器,统计小写字母数。
    const char str[] = "I am a slow walker, but I never walk backwards.";

    while(str[i])
    {
        if(islower(str[i]))
            ++count;
        ++i;
    }

    printf("There are %d lowercase letters in the sentence.", count);

    return 0;
}

输出:

There are 34 lowercase letters in the sentence.


相关内容:
isupper 检查字符是否为大写字母的函数。
isalpha 检查字符是否为字母的函数。
isalnum 检查字符是否为字母或者十进制数字字符的函数。