#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
char str[50];
int count[26] = {0};
int x;
int len;
int max;
printf("Enter your input: ");
scanf("%s", str);
while( ! feof(stdin)) {
len = strlen(str);
for(x = 0; x < len; ++x) {
char ch = str[x];
int sub = ch - 97;
count[sub] = count[sub] + 1;
}
scanf("%s", str);
}
max = count[0];
for(x = 0; x < len; ++x) {
if(count[x] > max){
max = count[x];
}
}
printf("Missing letters: ");
for(x = 0; x < 26; ++x) {
if(count[x] == 0) {
x = x + 97;
printf("%c", x);
}
}
printf("\n");
return 0;
}
我是C
新手,我已经尝试解决这个问题几个小时了,但我只是不明白。我认为问题出在 while
循环上,但我刚刚开始编码,我不知道。有什么东西会跳到任何人身上吗?这应该读取一个句子并输出未看到的字母。谢谢。
最佳答案
您的 while 循环仅在存在 EOF 时终止。使用Ctrl^D发送EOF信号来转义feof函数。
关于有人可以帮我找出为什么没有输出吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48835963/