c - while(getchar() != 多个参数)

标签 c while-loop getchar

如何使用 getchar 作为 while 循环的条件并使其在 (c=getchar()) = EOF 或 '\n' 或 '\0' 时终止。

我试过:

int c=0;
while((c=getchar()) != EOF || '\n' || '\0'){
putchar();
}

这没有用,如果我输入:WEATHER(+enter)。它没有终止循环。

我怎样才能让它工作?

启发我

最佳答案

你可以使用这样的东西:

int c = 0;
while((c=getchar()) != EOF) {
  if ((c == 0) || (c == '\n'))
    break;
  putchar(c);
}

关于c - while(getchar() != 多个参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8027213/

相关文章:

c - 应该在 longjmp() 之后调用 free() 吗?

c - 为什么 makecontext 不适用于 pthreads

c - setvbuf 无法使标准输入无缓冲

java - 如何将我的 Collat​​z 序列代码停止在 1?

c++ - 如何在不中断剩余代码的情况下仅 cin C++ 中的整数?

c - getchar() 函数的奇怪行为

C 代码、scanf 和 getchar

c - 数组的最大值和最小值

c - 如何修复C中的 "Error enabling this function: Address exceeds the allowed range"

java - 更改/增加方法内 while 循环条件的值 - 好或坏 -