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.
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.
You can use the setvbuf function:
setvbuf(stdout, NULL, _IONBF, 0);
Here're some other links to the function.
You can also use setbuf
setbuf(stdout, NULL);
This will take care of everything
Use fflush(FILE *stream)
with stdout
as the parameter.
You can do this:
write(1, ".", 1);
instead of this:
printf(".");
Use fflush(stdout)
. You can use it after every printf
call to force the buffer to flush.