my question is about how EOF is interpreted in the middle of an input, here is an example:
int main() {
int a, b;
printf("enter something >\n");
scanf("%d", &a);
while((b = getchar()) != EOF) {
printf("%i\n", b);
}
return b;
}
I run the program and enter:
1hello^Z(control+z)abc
the output is:
104 (ascii number for h)
101 (for e)
108 (l)
108 (l)
111 (o)
26 (what is this?)
The digit 1 is read by scanf, the remaining stays in the buffer, getchar() gets all of them until ^Z, which is expected behavior, as the control z closes stdin. however where does 26 come from? If the last thing getchar() reads is EOF why isn't -1 the last value? Also why doesn't this program get out of the loop when it reads ^Z, why do I need to invoke EOF one more time with control z to terminate the loop? 26 is the ascii for SUB, I don't know what to make of this.
Thank you.