Possible duplicate:Why is printf not reset after a call if a new line is not specified in the format string?
When I run something like
for (i = 1; i <= 10; i++) { sleep(1); printf("."); }
what I expect will be one dot per second ten times. What I get is ten points once every ten seconds. Why is this so, and how to make the program actually print one dot (or do other things) every second (or a different time interval)?
printf() performs data buffering, you can force reset this data using fflush(stdout) :
printf()
fflush(stdout)
for (i = 1; i<=10; i++) { sleep(1); printf("."); fflush(stdout); }