Two different things are happening.
Typing Control-Z in Windows or Control-D in Linux triggers an end-of-file condition and causes getchar()
to return the value EOF
.
Typing Control-Z in Linux does something different: it suspends the execution of your program. After typing Control-Z, if you type the jobs
command, it will show your suspended program. Typing fg
will cause it to resume and continue accepting input -- until you signal an end-of-file condition by typing Control-D. That would be easier to see if your program generated some output.
The behavior of Control-Z isn't connected to the way your program is written; Control-Z will suspend (nearly) any running program, whether it's written in C or not, and whether it's waiting for input or not. That behavior is specific to Linux and other Unix-like operating systems.
You'll probably never run out of doubts and questions; I certainly haven't.