C continue after buffer clear

123 Views Asked by At

I'm using while(getchar()!= '\n'); to clear the buffer if the user inputs more than one character.

If more than one character is entered the program doesn't get stuck. But if one character is entered the program waits for me to hit enter to continue. How can i get it to continue even if only one character is entered? Thanks for any help provided!

1

There are 1 best solutions below

9
Weather Vane On

You can check the keyboard buffer before committing to a read

while (kbhit()) getch();