c编程问题,请高手指教!

来源:百度知道 编辑:UC知道 时间:2024/06/01 06:58:24
main()
{int ENG=0,eng=0,num=0,space=0,other=0;
char i,j,c[3][80];
clrscr();
for(i=0;i<3;i++)
for(j=0;j<80;j++)
scanf("%c",&c[i][j]);
for(i=0;i<3;i++)
for(j=0;j<80;j++)
if(c[i][j]>='A'&&c[i][j]<='Z') ENG++;
else if(c[i][j]>='a'&&c[i][j]<='z') eng++;
else if(c[i][j]>='0'&&c[i][j]<='9') num++;
else if(c[i][j]==32) space++;
else other++;
printf("\nENG=%d\neng=%d\nnum=%d\nspace=%d\nother=%d\n",ENG,eng,num,space,other);
}

输出时,连回车键也算作一个字符统计到了other中。如何才能不统计回车键?

作者的意思是否是连续输入几行字符,统计结果?很遗憾,我试验了一下上面几位的程序都不能得出正确结果,所以只好自己写了一个,在win-tc和Dev-c++下通过,且执行正确。gets()函数以回车键作为输入一行的结束,故回车符不会被统计。
# include <stdio.h>
# include <stdlib.h>
# include <conio.h>
# define NUM 80
main()
{int ENG=0,eng=0,num=0,space=0,other=0;
int i,j;
char c[3][NUM];

for(i=0;i<3;i++)
{gets(c[i]);
for (j=0;c[i][j]!='\0';j++)
{if(c[i][j]>='A'&&c[i][j]<='Z') ENG++;
else if(c[i][j]>='a'&&c[i][j]<='z') eng++;
else if(c[i][j]>='0'&&c[i][j]<='9') num++;
else if(c[i][j]==32) space++;
else other++; }
}
printf("\nENG=%d\neng=%d\nnum=%d\nspace=%d\nother=%d\n",ENG,eng,num,space,other);
getch();
}

用getchar()把回车读了

楼上正解,加个getchar() 吃掉回车就好
#include<stdio.h>
main()
{int ENG=0,eng=0,num=0,space=0,other=0;
ch