keypressed()

Phil McDonald phil at galbp.LBP.HARRIS.COM
Tue Feb 23 03:02:25 AEST 1988


In article <136 at forty2.UUCP> eschle at forty2.UUCP (Patrik Eschle) writes:
>How do I write a function keypressed(), that returns 0 if no
>char is in the input queue and returns the character otherwise?
>Keypressed() should not block, and should leave the terminal in its
>initial state after returning.
>
>I can't use curses and have played around with ioctl, but its
>really slow.
>
>Any suggestions?                   Patrik 

===========================================================================
I would suggest using the rdchk(s) command.

Keypressed()
{
char	c;

	if (rdchk(stdin) > 0) {
		read(stdin, &c, sizeof(char));
		return(c);
	}
	else
		return(0);
}



More information about the Comp.lang.c mailing list