I have a program that outputs a menu, the input should be a char from stdin. Naturally, I would think to use getchar(). Are you supposed to do the following every time after you are finished getting the character?
I was googling around and I found fflush(stdin). Unfortunately, the behavior of flushing stdin is undefined, so there goes that idea.Code:while (getchar() != '\n') continue;
What's the best alternative to using getchar to read character input. Or, do you just have to be prudent to clear stdin of newline characters.