C stdio – disable buffering

Sometimes it’s useful to disable buffering for printf/fprintf etc. This is especially the case when you’re trying to debug a program and you’re not sure if it’s going to exit prematurely, before the output buffer gets flushed.

It’s a pain to stick fflush() after every fprintf. The proper way to do it is:

setbuf(stream, NULL);

The manpage assures us this is equivalent to the more verbose

setvbuf(stream, NULL, _IONBF, BUFSIZ);
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *