Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!cs.utexas.edu!uunet!crdgw1!sungod!davidsen From: davidsen@sungod.crd.ge.com (ody) Newsgroups: comp.lang.c Subject: Re: ReadKey like Function in C Message-ID: <1703@crdgw1.crd.ge.com> Date: 16 Aug 89 14:39:45 GMT References: <148@trigon.UUCP> <225800206@uxe.cso.uiuc.edu> <1677@crdgw1.crd.ge.com> <19095@mimsy.UUCP> Sender: news@crdgw1.crd.ge.com Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric Corp. R&D, Schenectady, NY Lines: 39 In article <19095@mimsy.UUCP> chris@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@crdos1.crd.GE.COM) {uunet | philabs}!crdgw1!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me