曲径通幽论坛

标题: islower() -- 测试小写字母 | isupper() -- 测试大写字母 [打印本页]

作者: beyes    时间: 2011-12-17 12:32
标题: islower() -- 测试小写字母 | isupper() -- 测试大写字母
islower()isupper() 的函数原型如下:
[C++] 纯文本查看 复制代码

#include <ctype.h>
int islower(int c);
int isupper(int c);

该函数对参数 c 进行测试,如果是小写字母则返回 TRUE,否则返回 NULL 。该函数也是个宏函数。

测试代码
[C++] 纯文本查看 复制代码
#include <stdio.h>
#include <ctype.h>

int main()
{
        char str[] = "AbCd1E#f?i";
        int i;

        for ( i = 0; str != 0; i++)
                if (islower(str))
                        printf("%d is a lowercase character:%c\n", i, str);

        printf ("----------------------------\n");

        for (i = 0; str != 0; i++)
                if (isupper(str))
                        printf ("%d is a uppercase character:%c\n", i, str);

        return 0;
}

运行输出:
./islowup
1 is a lowercase character:b
3 is a lowercase character:d
7 is a lowercase character:f
9 is a lowercase character:i
----------------------------
0 is a uppercase character:A
2 is a uppercase character:C
5 is a uppercase character:E





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2