| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 848 人关注过本帖
标题:问一下c-'0'表示什么?
取消只看楼主 加入收藏
mscool
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2013-5-9
结帖率:92.31%
收藏
已结贴  问题点数:20 回复次数:2 
问一下c-'0'表示什么?
#include <stdio.h>
   /* count digits, white space, others */
   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);
   }



这个代码中 ++ndigit[c-'0'];怎么理解?直接++ndigit[c]不行吗?c-'0'表示什么?
搜索更多相关主题的帖子: include others white 
2013-05-14 13:48
mscool
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2013-5-9
收藏
得分:0 
回复 2楼 Ryker
数组的下标是正整数不就行了吗?
2013-05-15 14:25
mscool
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2013-5-9
收藏
得分:0 
回复 2楼 Ryker
懂了  谢谢
2013-05-15 15:15
快速回复:问一下c-'0'表示什么?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014226 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved