写一个程序统计输入字符串中:
各个数字、空白字符、以及其他所有字符出现的次数。
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>//isspace(),isdigit()
int main()
{
int space = 0;
int other = 0;
int arr[10] = { 0 };
int ch = 0;
int i = 0;
while ((ch = getchar()) != EOF)
{
if (isspace(ch))
{
space++;
}
else if (isdigit(ch))
{
arr[ch - ‘0‘]++;
}
else
other++;
}
printf("space:%d\n", space);
printf("other:%d\n", other);
for (i = 0; i < 10; i++)
{
printf("%d:%d\n", i, arr[i]);
}
system("pause");
return 0;
}本文出自 “无以伦比的暖阳” 博客,请务必保留此出处http://10797127.blog.51cto.com/10787127/1716186
原文:http://10797127.blog.51cto.com/10787127/1716186