首页 > 其他 > 详细

一个关于字符串统计的程序

时间:2015-10-22 17:32:45      阅读:194      评论:0      收藏:0      [点我收藏+]


编写一个程序统计输入字符串中:
各个数字、空白字符、以及其他所有字符出现的次数。
#include <stdio.h>
 
int main()
{
         int ch= 0;
         intspace = 0;
         intother = 0;
         int i =0;
         intnum[10] = {0};
         while((ch = getchar()) != EOF)
         {
                   if(isspace(ch))
                   {
                            space++;
                   }
                   elseif (ch >= ‘0‘&& ch <= ‘9‘)
                   {
                            num[ch - ‘0‘]++;
                   }
                   else
                   {
                            other++;
                   }
         }
         for (i= 0; i < 10; i++)
         {
                   printf("%d--->%d\n", i, num[i]);
         }
         printf("space= %d\n", space);
         printf("other= %d\n", other);
         system("pause");
         return0;
}
 
运行结果为:


技术分享

一个关于字符串统计的程序

原文:http://760470897.blog.51cto.com/10696844/1705269

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!