"... both fflush and fpurge will discard any unwritten or unread data in the buffer ...": None.
fflush :
The fflush function forces all buffered data to be written for a given output or update stream through the write function underlying the stream. The open status of the stream does not change. If the stream argument is NULL , fflush clears all open output streams.
fpurge :
The fpurge function erases any input or output buffered in this stream. For output streams, this discards any unwritten output. For input streams, this discards any input read from the base object but not yet received using getc . This includes any text discarded using ungetc . (PS: there is also __fpurge , which does the same, but returns no value).
In addition to the obvious effect on buffered data, use wherever you notice the difference with input streams. You can fpurge one such stream (although this is usually a mistake, perhaps a conceptual one). Depending on the environment, you may not fflush input stream (its behavior may be undefined, see the man page ). In addition to the above differences: 1) the cases where they lead to errors are different, and 2) fflush can work in all output streams with one statement, as said (this can be very useful).
As for the pros and cons, I would not quote any at all ... they just work different (mostly), so you should know when to use them.
In addition to the functional difference (what you requested) there is a portability difference: fflush is a standard function, and fpurge is not (and __fpurge too).
Here you have the relevant manual pages ( fflush , fpurge ).
source share