Re: WOT: Testing stdin

New Message Reply Date view Thread view Subject view Author view

Shankar N Swamy (shankar.n.swamy++at++boeing.com)
Wed, 23 Jun 1999 18:49:46 -0700


Thom DeCarlo wrote:
>
>
> The problem is, how do I test whether anything has been typed to stdin
> without blocking the program if the input buffer is empty? Of course,
> the simple things don't work. I've tried getc(), fgetc(), gets(),
> scanf(), .... They all block until a '\n' is typed. I just want the test
> to fail and continue if nothing is waiting in the buffer.
>

What exactly do you want to do? If you just want the characters to be
processed as they are typed in, without waiting for the end of the line,
from the program kick-off till it exits, then put the terminal into
cbreak mode (man cbreak).

If you want to process the input the normal ("canonical") way most of
the times, but only intermittently want to process without waiting for
the end of the line, you can flush the terminal's input queue using
the 'tcflush' function (man tcflush).

>
> Any ideas from you C++ gurus out there?
>

As you notice, this is an operating system issue and not a C/C++ issue.

shankar

--------------------------------------------------------------------------
shankar.n.swamy++at++boeing.com Shankar N. Swamy
                              Computer Graphics & VR Research
PHONE: (425) 865-4286 Mathematics & Computing Technology
FAX : (425) 865-2965 Phantom Works, Boeing
                              PO Box 3707 MS 7L-48, Seattle, WA 98124-2207
---------------------------------------------------------------------------


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Wed Jun 23 1999 - 18:49:53 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.