Output to stdout
(which is where printf
writes) is by default (when connected to a terminal) line buffered. That means output is flushed (actually written to the terminal) either when the buffer is full, when you print a newline, or when you explicitly flush it (with fflush).
In your case, since you never fill the buffer and don't print newlines, you need to explicitly call fflush(stdout)
before each call to sleep
.