无法重现您的错误。我添加了一些调试语句,
#include <stdio.h>
main() {
int nc = 0, ch;
while ((ch = getchar()) != EOF) {
printf("%d\n", ch);
++nc;
}
printf("nc - %1d\n", nc);
}
然后gcc
在 Windows 上进行了尝试:
E:\temp>gcc eof.c
E:\temp>a
^Z
nc - 0
E:\temp>a
foo bar
102
111
111
32
98
97
114
10
^Z
nc - 8
然后使用 Visual Studio 2008:
E:\temp>cl eof.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
eof.c
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:eof.exe
eof.obj
E:\temp>eof
^Z
nc - 0
E:\temp>eof
foo bar
102
111
111
32
98
97
114
10
^Z
nc - 8