我一直在阅读K & R的The C Programming Language。当我在示例程序输入17页的计算行,程序总是结果总是0。这里是我的代码:17行计数程序结果始终为0
/* Taken from The C Programming Language by Brian W. Kernighan and
* Dennis M. Ritchie */
/* Include statement added for compatibility */
#include "stdio.h"
main() /* count lines in input */
{
int c, nl;
nl = 0;
/* EOF in Linux is ctrl-D and ctrl-Z on Windows */
while ((getchar()) != EOF)
if (c == '\n')
++nl;
printf("%d\n", nl);
}
这段代码在各方面都与K&R版本相同吗? – 2014-10-03 01:11:51
不,我从下面的答案中可以看到错误的输入。我仍然不敢相信它是诚实的。我一遍又一遍地看了半个小时,仍然错过了我的错误。不过谢谢你的回复。很抱歉这么做。 – Guest123ABC 2014-10-03 01:29:03