JUAN DENT wrote: |
---|
Cubbi do you know how this eof works in Windows? at the system level? |
no, but I just looked it up.
In the Windows Console, Ctrl-Z has no magic powers (unlike Ctrl-D on Linux): it actually creates a regular ASCII character code \x1A and puts it on the input line. You can keep typing after that, and press more Ctrl-Z, and keep building up the line of input. You need to press the Enter key to send the line to the program.
When the Windows C library processes the line buffer it got from the console (via WinAPI call ReadFile), it treats \x1A as a physical "end of file" character (for backwards compatibility with the long-extinct operating system CP/M).
* If \x1A is first in the line, C layer returns EOF and you're done.
* If \x1A is not the first character on the line of input, C processes the characters in the buffer up to and including the first \x1A, and throws away the rest of the line (including the \n, so if you read with something like getline(), you will need to press Enter again to see the line)
This is also the reason you can't read binary files on Windows in text mode: the first time you hit a \x1A, the read throws away the rest of the file (on Linux, and all POSIX systems, there is no distinction between binary and text mode)