C Input Question?

Philip W. Servita meister at faron.UUCP
Tue Mar 5 02:26:31 AEST 1985


>> I am working an a very simple game using graphics text with a
>> GiGi terminal.  I am having a big problem with the input.  When
>> I get to a read, or any input statment, in C, everything stops
>> and waits for the input.
>> 
>[text cut for brevity. Scott wants non-blocking I/O, that is "read if
>data, but don't wait for data.]
>>
>> Is there an easy way to do this in C.  
>> I am doing this on a VAX running 4.2 if that makes a difference.  
>>
>> scott hossler
>> rochester!ritcv!sah9577


i did this once i a game program also. try the following:

#include <sgtty.h>

...

char 
inkey()

{

   long charwaiting;
   char getchar();

   ioctl(0,FIONREAD,&charwaiting);

   if(charwaiting) return(getchar());   
 
   return((char) 0);

}

returns the next character on the stdin stream if there is one, 0 otherwise.
this will only work in cbreak or raw mode. look up tty(4) for details.

                                        -the venn buddhist
-- 
---------------------------------------------------------------------
         is anything really trash before you throw it away?
---------------------------------------------------------------------



More information about the Comp.lang.c mailing list