test whether or not a keyboard stroke is available
#include <conio.h> int kbhit( void );
The kbhit() function tests whether or not a keystroke is currently available. When one is available, the function getch() or getche() can be used to obtain it.
With a stand-alone program, the kbhit() function can be called continuously until a keystroke is available.
The kbhit() function returns zero when no keystroke is available; otherwise, it returns a non-zero value.
getch(), getche(), putch(), ungetch()
/*
* This program loops until a key is pressed
* or a count is exceeded.
*/
#include <stdio.h>
#include <conio.h>
void main()
{
unsigned long i;
printf( "Program looping. Press any key.\n" );
for( i = 0; i < 10000; i++ ) {
if( kbhit() ) {
getch();
break;
}
}
}
WATCOM
All (except Netware, DOS/PM)