简体   繁体   中英

How to turn off buffering of stdout in C

I want to turn off the buffering for the stdout for getting the exact result for the following code

while(1) {
printf(".");
sleep(1);
}

You can use the setvbuf function<\/a> :

setvbuf(stdout, NULL, _IONBF, 0);

You can also use setbuf

setbuf(stdout, NULL);

This will take care of everything

Use fflush(FILE *stream) with stdout as the parameter.

http://www.elook.org/programming/c/fflush.html

You can do this:

write(1, ".", 1);

Use fflush(stdout)<\/code> . You can use it after every printf<\/code> call to force the buffer to flush.

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM