The problem is that some characters may already be present in the input buffer.
Depending on many buffered inputs are there you need more getchar.
A simple solution is to loop while a '\n' is ecountered de facto empting also the buffer:
int c;
do
c=getchar();
while (c!=EOF && c!='\n');
Another really classic solution (coming from DOS times, but still working) is:
while(_kbhit())
_getch();
With the latter solution you don't need to have a '\n' in the stream buffer.