C equivalent of autoflush (flush stdout after each write)?

raldi picture raldi · Oct 18, 2008 · Viewed 10k times · Source

In Perl, I can type:

$|++;

and anything printed to STDOUT will be automatically fflush()ed.

Is there an equivalent in C? In other words, is there some way I can tell stdio to automatically fflush stdout after every printf(), the way it automatically flushes stderr?

Answer

Harry picture Harry · Oct 18, 2008

Try setvbuf(stdout, NULL, _IONBF, 0). It changes stdout to unbuffered (_IONBF) mode.