I tested this code:
1 #include <stdio.h>
2
3 main()
4 {
5 int c;
6
7 while ((c = getchar()) != EOF) {
8 putchar(c);
9 printf("%d ", c);
10 }
11 printf("%d\n", c);
12 }
Question:
When I inputted a line of characters, and then inputted an 'enter', I got this kind of result:
asdf
a97 s115 d100 f102
When I added an EOF(ctrl+d) directly behind a line of characters, I got the result directly behind the input, like:
asdfa97 s115 d100 f102
My questions are whether the 'enter' triggered the code running? Why when I input an EOF, was not the 'enter' needed to output the result? Why did I need another EOF to quit running?
Thanks a lot.