ReadKey like Function in C

ody davidsen at sungod.crd.ge.com
Thu Aug 17 00:39:45 AEST 1989


In article <19095 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:

| What does `kbhit()' mean when stdin is a socket?  How about in a VMS
| batch job?

  kbhit() returns true if a single character blocking read would return
data right now. This seems to be pretty well defined for batch, pipe,
socket, etc.
| 
| What does getch() do at end of file?

  A good point. As it's intended to be used, there is no end of file...
the user can always type another character. I don't think anyone would
object if the definition were extended to allow it to return EOF (it's
already an int, so that is a legal thing to do). Currently the MSC
version hangs on input waiting for more data.

  I don't see any great dificulties in implementing these with streams,
etc, either. The object of kbhit() is to determine if a read will block
or get data, and the object of getch is to read just one character, with
no echo (assuming that echo is taking place at all). Both of these
things can be done on most hosted systems, as evidenced by programs
which do them. The MSC version included conio.h, and if an environment
can't provide the service it doesn't provide the header.

  This whole issue is really "my brain-damaged o/s can't do a lot of
things, don't put them in the standard." Rather than avoid defining a
standard for these commonly needed functions, it seems better to adopt
the principle of defining how they should be done, and leaving the
vendor to admit deficiencies in the o/s if they can't.

  Long global names seem to fall in this category, too. At some point
X3J11 should just add them to the standard, and let vendors run a long
to short name conversion as part of the compilation process. It can be
done.

	bill davidsen		(davidsen at crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list