C语言 请帮我分析下这个程序:有一篇文章,共有三行文字,每行有80个字符,要求分别统计出其中....

#include <stdio.h>
main()
{
int upper,lower,digit,space,other,i,j;
upper=lower=digit=space=other=0;
char a[3][80]={'\0'};
printf("请输入三段文字:\n");
for(i=0;i<3;i++)
for(j=0;(a[i][j]=getchar())!='\n';j++)
{
if(a[i][j]>='a'&&a[i][j]<='z')
lower++;
else if(a[i][j]>='A'&&a[i][j]<='Z')
upper++;
else if(a[i][j]>='0'&&a[i][j]<='9')
digit++;
else if(a[i][j]==' ')
space++;
else
other++;
}
printf("这三行文字中共有:\n小写字母:\t%d\n大写字母:\t%d\n数字:\t\t%d\n空格:\t\t%d\n其他字符:\t%d\n",lower,upper,digit,space,other);
return 0;
}

有什么问题么?没看出来有明显的错误啊追问

这不是我编的,但这程序不能完全看明白。

追答

for(j=0;(a[i][j]=getchar())!='\n';j++)
{
if(a[i][j]>='a'&&a[i][j]='A'&&a[i][j]='0'&&a[i][j]<='9')
digit++;
else if(a[i][j]==' ')
space++;
else
other++;
}
就是这个循环,一个一个子复读然后判断属于什么类型的字符

追问

后面other不能定义吗?

追答

other是其它字符 你要想定义可以再加判断语句
比如 else if(a[i][j]=='*')
star++;

温馨提示:答案为网友推荐,仅供参考
相似回答