本人学生课本有一道题
请编写程序,实现统计字符串s中数字字符‘0’~‘9’出现的次数,并依次存储在长度为10的数组count中。
以下是本人编写的程序,请指教。
#include <stdio.h>
void main()
{
char c;
int count[10] = {0,0,0,0,0,0,0,0,0,0};
printf("请输入任意字符(输入*终止)\n");
while ((c = getchar()) != '*');
{
if (c == 0)
count[0]++;
else if (c == 1)
count[1]++;
else if (c == 2)
count[2]++;
else if (c == 3)
count[3]++;
else if (c == 4)
count[4]++;
else if (c == 5)
count[5]++;
else if (c == 6)
count[6]++;
else if (c == 7)
count[7]++;
else if (c == 8)
count[8]++;
else if (c == 9)
count[9]++;
else;
}
printf("%d %d %d %d %d %d %d %d %d %d", count[0], count[1], count[2], count[3], count[4], count[5], count[6], count[7], count[8], count[9]);
}
正常应该是输入55566677789输出0000033311,可是每次不够输入什么输出都为0000000000