有人可以帮我找出为什么没有输出吗?

标签 c

#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/

相关文章:

c - Unix C 套接字服务器不接受连接

c - 为什么 c 中的整型变量在将字符值传递给它后会打印其旧值?

c++ - 清除 Linux 内核链表

c - SetWindowLongPtr 返回 ERROR_ACCESS_DENIED

c++ - 通过指针访问值与存储为临时值的效率

c - 给定指针的地址,我如何获得它指向的内容?

c - 堆栈和堆内存的大小

c - Visual Studio 2010 运行时检查失败 #3

无法找出共享变量的错误

python - 使用特定的 python 导入调用 PyModule_GetDict() 时出现异常