Reputation: 2019
I want to turn off the buffering for the stdout for getting the exact result for the following code
while(1) {
printf(".");
sleep(1);
}
The code printf bunch of '.' only when buffer gets filled.
Upvotes: 53
Views: 57358
Reputation: 94279
You can use the setvbuf function:
setvbuf(stdout, NULL, _IONBF, 0);
Here're some other links to the function.
Upvotes: 129
Reputation: 3519
Use fflush(stdout)
. You can use it after every printf
call to force the buffer to flush.
Upvotes: -14
Reputation: 2645
Use fflush(FILE *stream)
with stdout
as the parameter.
http://www.elook.org/programming/c/fflush.html
Upvotes: -3
Reputation: 121
You can do this:
write(1, ".", 1);
instead of this:
printf(".");
Upvotes: -3
Reputation: 2646
You can also use setbuf
setbuf(stdout, NULL);
This will take care of everything
Upvotes: 28