#include <stdio.h>
int main(){
int i = 0;
int count[26] = {0};
char str[100];
printf("Ord: ");
scanf("%s", &str);
printf("Frekvens: n");
while (str[i] != ' '){
if (str[i]>= 'a' && str[i] <= 'z'){
int x = str[i] -'a';
count[x]++;
}
i++;
}
for (i = 0; str[i] != 0; i++){
printf("'%c' : %dn", i + 'a', count[i]);
}
return 0;
}
如何看到所有的字母在字母表打印时运行这个?和for循环有关吗?
打印循环应该遍历count
的索引。
for (i = 0; i < 26; i++){
printf("'%c' : %dn", i + 'a', count[i]);
}