| 
 | 
 
 
发表于 2022-11-20 21:51:42
From FishC Mobile
|
显示全部楼层
|阅读模式
 
 
 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
怎么样才能实现显示这个二维数组中大写字母,小写字母,空格,数字 和其它字符的个数呀,我的这个程序有什么问题呀。求大佬指导() 
 
#include<stdio.h> 
int main() 
{ 
    char t[3][40]; 
    int i = 0, j = 0, y = 0, x = 0, num = 0; 
    int capital = 0, lowercase = 0, space = 0, other = 0; 
    for (i = 0; i < 3; ++i) { 
        for (j = 0; j < 40; x++) { 
            t[i][j] = getchar(); 
            if (t[i][j] == '\n') break; 
        } 
    } 
 
    for (x = 0; x < 3; x++) { 
        y = 0; 
        while (t[x][y] != '\n') { 
            if (t[x][y] >= 'A' && t[x][y] <= 'Z') { 
                capital++;  y++; 
            } 
            else if (t[x][y] >= 'a' && t[x][y] <= 'z') { 
                lowercase++; y++; 
            } 
            else if (t[x][y] == ' ') { 
                space++; y++; 
            } 
            else if (t[x][y] >= '0' && t[x][y] < '9') { 
                num++; y++; 
            } 
            else { 
                other++; y++; 
            } 
        } 
    } 
    printf("大写字母有%d个,小写字母有%d个,空格有%d个,数字有%d个,其他字符有%d个", capital,lowercase,space,num,other); 
    return 0; 
} 
 |   
 
 
 
 |