flushing stdin

This is a discussion on flushing stdin within the C Programming forums, part of the General Programming Boards category; I prompt for input and the scanf function is skipped over because the stdin buffer contains data. How can I ...

flushing stdin

I prompt for input and the scanf function is skipped over because the stdin buffer contains data. How can I flush this beforehand? Everywhere I look tells me it's system dependent and I'm on linux and ncurses is recommended. There surely has to be a way in ansi c to do this.

Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie

int fflush(FILE *stream)
On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.