The likely reason is a line buffered stdout
, (this is implementation defined so I can't be 100% sure). In these implementations the content written to the buffer won't immediately be transferred to the output.
Using "\n"
, causes a flush of the buffer to the output and the printf
will print the contents, the downside is that the "\n"
will also be printed.
As an alternative, you can use fflush(stdout) if you don't want a that newline character to be printed.
For output streams (and for update streams on which the last operation was output), writes any unwritten data from the stream's buffer to the associated output device.