Exactly what it says on the tin. Is there a way for me to empty out the input buffer in preparation for further user input without using the undefined fflush(stdin) or a looped getchar()?
I'm trying to write a small input function that isn't vulnerable to buffer overflows. For this, I've used fgets(entered_text, 30, stdin); which works as promised.
However, in the event of overflow, I have stuff remaining in the input buffer that gets read when I next call the input function. I want to empty the buffer to avoid this.
fflush(stdin) is supported, but not defined. http://c-faq.com/stdio/stdinflush2.html suggests I use a loop of getchars, but the problem is that if the input buffer is empty, it will request a character and force me to press two 'enter's.
Is there a way for me to check if the input buffer is empty, or to empty it by other means?
Thanks in advance.