Alex Rivera | Logout

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

Asked 2008-10-18T00:36:58.093
34

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?

Edit
Report

1 Answer

45

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

answered 2008-10-18T00:45:41.117

Your Answer