C islower()

islower() 函数定义在 ctype.h 头文件中。它有助于检查指定字符是否为小写字母 (a-z)。


int islower( int argument ); #where argument will be a character
 

islower() 参数

islower() 函数接受一个参数,该参数为整数形式,返回值也应为整数。当传入一个字符时,它会被转换为对应其 ASCII 值的整数。

参数 描述 必需/可选
参数 要检查的字符 必需

islower() 返回值

如果给定字符是小写字母,islower() 返回一个非零整数,否则返回零。当传入一个小写字母字符时,我们将得到一个不同的非零整数。

输入 返回值
如果参数不是小写字母
非零数字 如果参数是小写字母

islower() 示例

示例 1:C 语言中 islower() 函数的工作原理


#include <stdio.h>
#include <ctype.h>
int main()
{
    char ch;

    ch='a';
    printf("If %c is passed to islower(): %d", ch, islower(ch));

    c='A';
    printf("\nIf %c is passed to islower(): %d", ch, islower(ch));

    return 0;
}

输出


If a is passed to islower(): 2
If A is passed to is islower(): 0

示例 2:C 语言中 islower() 函数如何工作?


#include <stdio.h>
#include <ctype.h>
int main()
{
    char ch;

    printf("Please enter a character: ");
    scanf("%c", &ch);

    if (islower(ch) == 0)
         printf("The given %c is not a lowercase alphabet.", ch);
    else
         printf("The given %c is a lowercase alphabet.", ch);

    return 0;
}

输出


Please enter a character: h
The given h is a lowercase alphabet.