I am running this example (from Kernighan and Ritchie's C book section 1.5.2) on a mac OS X machine terminal:
#include <stdio.h>
int main()
{
    int c, nl;
    nl = 0;
    while((c = getchar()) != EOF)
        if(c == '\n')
            ++nl;
    printf("%d\n", nl);
}
I run the app and enter the EOF character CTRL-D immediately. The program outputs 0D and terminates. The 0 is the expected output, but where does the extra 'D' come from? 
I saw this thread and this faq, but could not find an answer.
 
     
    