How to clear the key buffer while using kbhit() and getch()?

Whoever told you that kbhit() was a Windows function misinformed you kbhit() getch() and their relatives are actually part of the (C language bindings to the) MS-DOS API Their presence in the runtime libraries for OS/2, Win32, and other C/C++ compilers is simply to be a porting aid for MS/PC/DR-DOS programs The library maps them onto whatever native mechanism exists for accessing the keyboard, if there is one at all, and usually only in the right way for TUI, not GUI, applications to access the keyboard.

Whoever told you that kbhit() was a Windows function misinformed you. Kbhit(), getch() and their relatives are actually part of the (C language bindings to the) MS-DOS API. Their presence in the runtime libraries for OS/2, Win32, and other C/C++ compilers is simply to be a porting aid for MS/PC/DR-DOS programs.

The library maps them onto whatever native mechanism exists for accessing the keyboard, if there is one at all, and usually only in the right way for TUI, not GUI, applications to access the keyboard. If you're writing a new TUI application, don't use the MS-DOS API. Use the proper, native, API for the platform that you're targetting, such as the Win32 Console API or the OS/2 Console API, or the POSIX General Terminal Interface (via ncurses or some such).

When you do, you'll read their documentation and find out how to perform a destructive "get" of the keyboard input after doing a non-destructive "peek". Or indeed how to flush the buffer in its entirety if that is what you want to do.

The obvious choice would be FlushConsoleInputBuffer.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions