#include<stdio.h>
#include<ctype.h>//引用isspace函數的頭文件
#include<stdlib.h>
int main()
{
char ch,arr[10]={0};
int count=0,times=0,i;
while((ch=getchar())!=EOF)
{
if(ch>='0'&&ch<='9')
arr[ch-'0']++;//用下標標記法統計0~9出現的次數,注意此處要為arr[ch-'0']
else if(isspace(ch))//isspace函數判斷空白字符
count++;
else times++;
}
for(i=0;i<10;i++)
{
printf("%d出現的次數>%d\n",i,arr[i]);
}
printf("空字符出現次數>%d\n其他字符出現次數>%d\n",count,times);
system("pause");
return 0;
}
ctrl+z結束字符串的輸入。