[comp.lang.c] Some weird variant of getchar...

mndaily@ux.acs.umn.edu (Linda Seebach) (11/27/90)

Ok, I know this sounds stupid. However:

I have been looking, for ages, for a way of doing a non-waiting getchar.

Normally, getchar() waits until you give it a carriage return. If you are
in cbreak/raw mode (or something equivalent) it waits until you hit a
key. Is there any portable call (i.e., one that can be expected to work
on most computers, without hardware hacks) that will return *whether or not*
you have hit a key, and return a meaningful value? I would like to have such
a routine so I can check to see what the user wants to do without halting
my program. How is this done, pray tell?

--SeebS--
-- 
mndaily under *NO CIRCUMSTANCES WHATSOEVER* speaks for the Minnesota Daily.
Posts signed "--SeebS--" have no connection to Linda Seebach.
Any similarities to persons living or dead are ... oops

henry@zoo.toronto.edu (Henry Spencer) (11/28/90)

In article <2773@ux.acs.umn.edu> mndaily@ux.acs.umn.edu (Linda Seebach) writes:
>...Is there any portable call (i.e., one that can be expected to work
>on most computers, without hardware hacks) that will return *whether or not*
>you have hit a key, and return a meaningful value?

See the Frequently Asked Questions list.  (Hint:  the answer is "no".)
-- 
"I'm not sure it's possible            | Henry Spencer at U of Toronto Zoology
to explain how X works."               |  henry@zoo.toronto.edu   utzoo!henry

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (11/28/90)

In article <2773@ux.acs.umn.edu>, mndaily@ux.acs.umn.edu (Linda Seebach) writes:
> Ok, I know this sounds stupid. However:

> I have been looking, for ages, for a way of doing a non-waiting getchar.

There isn't any portable way of doing it in C, because some of the
operating systems C is available on cannot do it.  The best you can do
is make up two names (kb_getch, kb_ready, perhaps) and write an
implementation for each of the systems you are concerned with.

Perhaps it is time the net collaborated to produce model implementations
of these functions for MS-DOS, OS/2, VMS, BSD, S5, put them on a mail
server somewhere, and added the location to the FAQ?
-- 
I am not now and never have been a member of Mensa.		-- Ariadne.

drack@titan.tsd.arlut.utexas.edu (Dave Rackley) (11/28/90)

>> Ok, I know this sounds stupid. However:

>> I have been looking, for ages, for a way of doing a non-waiting getchar.

>   There isn't any portable way of doing it in C, because some of the
>   operating systems C is available on cannot do it.  The best you can do
>   is make up two names (kb_getch, kb_ready, perhaps) and write an
>   implementation for each of the systems you are concerned with.

>   Perhaps it is time the net collaborated to produce model implementations
>   of these functions for MS-DOS, OS/2, VMS, BSD, S5, put them on a mail
>   server somewhere, and added the location to the FAQ?

1.  I have it for VMS.  If there is interest I'll post it. 
 
2.  MS-Quick C v2.5 has the code for MS-DOS in a sample program, tools.c!

--

  DISCLAIMER?  I don't know anything 'bout any ol' disclaimer!         

+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| David Rackley		        |                                             |
| Applied Research Laboratories |        Remember, you can tuna fish,         |
| The University of Texas       |         But you can't tuna piano!           |
| Austin, TX.  78758            |                                             |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+