您的位置:首页 > 编程语言 > C语言/C++

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

2015-10-22 15:49 302 查看
编写一个程序统计输入字符串中:
各个数字、空白字符、以及其他所有字符出现的次数。
#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;
}

运行结果为:




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息