On Wed, 30 Dec 1998, Saraf Aalhad Ashok wrote:

> Dear friends,
> 
>  I can't locate a system call/library function equivalent to the kbhit()
> function provided on DOS platforms. Could you please tell me about such a
> function? I'm a novice when it comes to programming in C on the Linux
> platform.

There isn't one. 

Read the man page(s) for ncurses, specifically getch. Or if you
aren't linking against ncurses read the man page for termios and 
attempt to put the terminal in a not so cooked mode. 

Example:

/* untested */
int a_lame_kbhit_like_function(void)
{
unsigned char buffer[1];
struct termios OLDTSET, NEWTSET;
tcgetattr(0, &OLDTSET);
NEWTSET = OLDTSET;
NEWTSET.c_lflag  &= ~(ECHO | ICANON);

tcflush(fileno(stdin), TCIFLUSH)
tcsetattr(0, TCSANOW, &NEWTSET);
while(1)
        {
        if(-1 == read(fileno(stdin), buffer, 1))
                {
                if(errno == EINTR)
                        continue;
                return -1;
                }
        break;
        }
tcsetattr(0, TCSANOW, &OLDTSET);
return buffer[0];
}

Read the man pages to the above functions, to find out what 
headers to include. If you take time to read those man pages and 
other those listed in the "SEE ALSO" section, you'll find your
way around fairly quickly.





Reply via email to