I run this example (from Kernighan and Ritchie C, section 1.5.2) on a Mac OS X terminal:
#include <stdio.h>
int main()
{
int c, nl;
nl = 0;
while((c = getchar()) != EOF)
if(c == '\n')
++nl;
printf("%d\n", nl);
}
I launched the application and immediately entered the EOF symbol CTRL-D. The program displays 0Dand exits. 0 is the expected result, but where does the extra "D" come from?
I saw this thread and this faq , but could not find the answer.
Anand source
share