Unbuffered I/O using MicroSoft C 3.0

tom at uw-warp.UUCP tom at uw-warp.UUCP
Sun Jan 25 10:04:28 AEST 1987


In article <645 at uw-warp.UUCP>, I, tom at uw-warp.UUCP (Tom May), wrote:
> So, here is the promised routine which invokes MS-DOS to get a
> character from the keyboard (not stdin) without echoing it.  It also
> does some things which are obvious from looking at the code.
> 
> #include <dos.h>
> int
> grokchar() {
>     union REGS regs;
> 
>     regs.h.ah = 7;      /* get char no echo */
>     intdos (&regs, &regs);
>     return (regs.h.al == 26 ? EOF : regs.h.al == '\r' ? '\n' : regs.h.al);
> }

It turns out that the statement about reading the keyboard, not stdin, was
incorrect.  Although the function is called Direct Console Input or something
like that (my DOS machine + manuals are 15 miles away from my USENET machine),
further inspection of the DOS Technical Reference manual reveals that all those
so-called console routines actually read stdin.  Even the Keyboard Input
function reads stdin!  (At least the doc says it does, I haven't tried it.)
I discovered this when I redirected the input to a program I had written that
used the above function and found that it worked, much to my surprise.

Also, the MSC library routines getch() and getche() use DOS functions which
read characters from stdin, not con as the manual seems to imply.

I just wanted to clear this up before someone else made me look bad. :-)









-- 
Tom May.	uw-beaver!uw-nsr!uw-warp!tom



More information about the Comp.lang.c mailing list