有三行文字,每行最多80个字符,求其中大写字母,小写字母,数字,空格和其他

#include<stdio.h>
int main() {
    char text[3][20];//定义三行,每行最多不超过20个字符的二位数组
    char c;
    int i,j;

    int upCase,lowCase,num,space,others;
    upCase=lowCase=num=space=others=0;
    for(i=0;i<3;i++){
        gets(text[i]);
        for(j=0;j<20&&((c=text[i][j])!='\0');j++){
            if(c>='A'&&c<='Z'){
                upCase++;
            }else if(c>='a'&&c<='z'){
                lowCase++;
            }else if(c>='0'&&c<='9'){
                num++;
            }else if(c==' '){
                space++;
            }else {
                others++;
            }
        }
    }
    //upcase 大写字母 lowcase 小写字母 num 数字 space 空格 others 其他 
    printf("upCase=%d,lowCase=%d,num=%d,space=%d,others=%d",upCase,lowCase,num,space,others);

    return 0;
}
posted @ 2018-11-21 18:51  小Aer  阅读(195)  评论(0编辑  收藏  举报