【发布时间】:2012-08-27 16:50:35
【问题描述】:
我一直在阅读 Kernighan 和 Ritchie 的 The C Programming Language 并且很早就拥有了我遇到了一个不起作用的程序,即使我直接从书中复制了它。这是描述的屏幕截图 - http://i.imgur.com/SBQSE.png
它陷入了无限循环,因为我输入的任何内容显然都是键盘输入,并且它正在检查 EOF,这显然不是键盘输入。
#include <stdio.h>
/* copy input to output; 1st version */
main()
{
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
}
这样的 C 权威书籍肯定不会有错误,我是不是遗漏了什么?
【问题讨论】:
标签: c infinite-loop ansi