【发布时间】:2019-07-21 10:23:54
【问题描述】:
我是一名初级程序员(请原谅这个非常基本的问题),我正在通过 Kernighan 和 Ritchie 的书“C 编程语言”学习 C。
我从书中复制了这个程序,它编译得很好,但是当给出输入时,程序什么也不做。
#include <stdio.h>
int main() {
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%1d\n", nc);
}
输出应该是输入中的字符数,但什么都没有发生
【问题讨论】:
-
这里解释得很好getchar() != EOF
标签: c getchar kernighan-and-ritchie