有一篇文章,共有3行文字,每行小于80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。
请问我的代码哪里错了?感谢解答!
#include <stdio.h>
#include <string.h>
int main(){
char str[3][80];
gets(str);
int up=0,lo=0,di=0,sp=0,ot=0,i,j;
for(i=0;i<=2;i++)
{
for(j=0;j<=80;j++)
{
if(str[i][j]>='A'&&str[i][j]<='Z')up++;
else if(str[i][j]>='a'&&str[i][j]<='z')lo++;
else if(str[i][j]>='0'&&str[i][j]<='9')di++;
else if(str[i][j]==' ')sp++;
else ot++;
}
}
printf("upper case:%d\n",up);
printf("lower case:%d\n",lo);
printf("digit:%d\n",di);
printf("space:%d\n",sp);
printf("other:%d\n",ot);
}