C语言中,统计各个字符数量的程序,小甲鱼视频36章例题3

编写一个用来统计各个数字,空格符(空格,制表符,换行符)以及所有其他字符出现次数的程序。分别存储在变量num[10],blank,other中。

麻烦看下我遍的哪里不对
#include <stdio.h>

void main()

{
int c,blank,outher,i;
int num[10]={0};
blank=0;
outher=0;
while(c=getchar()!=EOF)
{
if(c>='0'&&c<='9')
{
num[c-'0']++;
}
if(c==' '||c=='\n'||c=='\t')
{
blank++;
}
else outher++;

}
for(i=0;i<10;i++)
{
printf("num[%d]=%d\n",i,num[i]);
}

printf("blank=%d,outher=%d\n",blank,outher);
}

你掉了else:
if(c>='0'&&c<='9')
{
    num[c-'0']++;
}
else if(c==' '||c=='\n'||c=='\t')
{
    blank++;
}
else outher++;

追问

加上之后也不对,这个题你编下看看

追答少了括号:
while((c=getchar())!=EOF)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-20
while((c=getchar())!=EOF)

亲, 你忘记了一个括号!导致运算顺全部改变了!
相似回答