#include
void main()
{
int c,nb,nt,nl,num,others;
nb=nt=nl=num=others=0;
while((c=getchar())!=EOF)
{
if(c==' ')
++nb;
else if(c=='\t')
++nt;
else if(c=='\n')
++nl;
else if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9')
++num;
else
++others;
}
printf("\n%d %d %d %d %d\n",nb,nt,nl,num,others);
}
这是原程序就是想实现能对输入的字符进行计数,为什么我输入“123空格回车ctrl+c”后能正常计数,但输入“123空格回车123wer【】ctrl+c”就不能计数出others的个数呢?我用调试能看出要输入回车后才能进入循环计数,那怎么能解决这个问题呢?