行计数程序:
1 #include
2
3 main()
4 {
5 int c, nl;
6
7 nl = 0;
8 while ((c = getchar()) != EOF);
9 if (c == '\n')
10 ++nl;
11 printf("%d\n", nl);
12 }
13
执行:
Press ENTER or type command to continue
\n
\n
\n
\n
0
shell returned 2
Press ENTER or type command to continue
Press ENTER or type command to continue
a
a
a
a
0
shell returned 2
最后一行按crtl+d,为什么都是0。还有最后的shell returned为什么是2?谢谢