Hello,
I tried the following code to experiment with EOF:
Code:
int c;
while(1)
{
printf("<GET>");
c = getchar();
if (c == EOF) {
printf("<EOF>");
}
printf("<PUT>");
putchar(c);
}
When I ran the program and typed asd and pressed CTRL+D (EOF), I got the following output:
<GET>asd<PUT>a<GET><PUT>s<GET><PUT>d<GET>
No EOF value was passed to the program. So far so good, I understand. When I pressed CTRL+D (EOF) again with no text entered, I expected EOF to be passed to the program which happened but the <EOF> text wasn't printed - I tried setting a breakpoint on the printf line and it did trigger yet nothing was printed. Why?
When I add the break command after the call to printf, the <EOF> text gets printed when I repeat the above procedure (run, type asd, press CTRL+D twice).
I'm totally confused...
EDIT: I'm using a *nix system, not Windows.