首页 新闻 赞助 找找看

c语言 统计数字、空白符、以及所有其他字符出现的次数

0
悬赏园豆:5 [已解决问题] 解决于 2012-10-18 20:21

#include "stdio.h"
void main()
{
    int c,i,nwhite,nother;
    int ndigit[10];
    nwhite=nother=0;
    for(i=0;i<10;++i)
          ndigit{i}=0;
    while((c=getchar())!=EOF)
    if (c>='0'&&c<='9')
    ++ndigit[c-'0'];
    else if (c==''||c=='\n'||c=='\t')
    ++nwhite;
    else
    ++nother;
    printf("digits=");
    for(i=0;i<10;++i)
    printf("%d",ndigit[i]);
    printf(",white space=%d,other=%d\n",nwhite,nother);
   
}

不知道哪错了,提示是第八行少了一个冒号,没看懂

轉身、錯過的主页 轉身、錯過 | 初学一级 | 园豆:189
提问于:2012-10-18 17:04
< >
分享
最佳答案
0
#include "stdio.h"
void main()
{
    int c,i,nwhite,nother;
    int ndigit[10];
    nwhite=nother=0;
    for(i=0;i<10;++i)
          ndigit[i]=0;
    while((c=getchar())!=EOF)
    if (c>='0'&&c<='9')
    ++ndigit[c-'0'];
    else if (c==' '||c=='\n'||c=='\t')
    ++nwhite;
    else
    ++nother;
    printf("digits=");
    for(i=0;i<10;++i)
    printf("%d",ndigit[i]);
    printf("white space=%d,other=%d\n",nwhite,nother);
    
}
收获园豆:5
星空雾雨 | 菜鸟二级 |园豆:311 | 2012-10-18 18:25

else if (c==' '||c=='\n'||c=='\t')
为啥我敲这一行不对呀,是英文打的呀

轉身、錯過 | 园豆:189 (初学一级) | 2012-10-18 20:11

@轉身、錯過: else if (c==' '||c=='\n'||c=='\t')这个c==' '中间要保证有空格,你打个空格键在里面

c='  '

星空雾雨 | 园豆:311 (菜鸟二级) | 2012-10-18 20:18

@星空雾雨: ok谢

轉身、錯過 | 园豆:189 (初学一级) | 2012-10-18 20:21

@轉身、錯過: 刚才发现这个程序实现了个啥呀……然后运行之后输入之后没反应了

轉身、錯過 | 园豆:189 (初学一级) | 2012-10-18 22:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册