#include <stdio.h>
#include <conio.h>
#include <string.h>
main() {
char s[200];
scanf("%s", &s);
int counter[255];
int n = sizeof(counter) / sizeof(counter[0]);
for (int i = 0; i < n; i++) {
counter[i] = 0;
}
for (int i = 0; i < strlen(s); i++) {
if (s[i] == 32) {
break;
}
int temp = (int)s[i];
counter[temp]++;
}
for (int j = 0; j < n; j++)
if (counter[j] > 0) {
printf("There are %d occurence of %c\n", counter[j], j);
}
}
这是一个简单的程序,用于计算字符在字符串中出现的次数。如果输入是单个单词(没有空格),它可以很好地工作。我知道空间的ASCII值是32,它应该出现,但它没有。