Streams and buffering problem
I have this problem in my code where I scanf a %d value, and if it is not converted I want to flush stdin and return to the main menu where a choice is presented.
Problem is that if the error condition occurs (say I enter "eep"), I return to the main menu with those characters on the stream and so scanf picks them up, and since 'e' is one of the menu options the case statement is triggered.
I thought that fflush(stdin) would do the trick, but apparently on GNU libc this only causes the contents of the buffer to be written to the stream.
Now I don't know much about buffered I/O, but i'm pretty sure what I want to do is also clear the stream somehow so subsequent calls to scanf don't pick up stray chars.
Hope someone can help with this.