Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!ames!ucbcad!zen!ucla-cs!alex From: alex@CS.UCLA.EDU Newsgroups: comp.lang.c Subject: Re: HELP!! (Reading one character) Message-ID: <9176@shemp.UCLA.EDU> Date: Fri, 13-Nov-87 05:58:04 EST Article-I.D.: shemp.9176 Posted: Fri Nov 13 05:58:04 1987 Date-Received: Sun, 15-Nov-87 11:11:10 EST References: <10318@brl-adm.ARPA> Sender: root@CS.UCLA.EDU Reply-To: alex@CS.UCLA.EDU (Alex Quilici) Organization: UCLA Artificial Intelligence Lab Lines: 43 Summary: Turbo C In article <10318@brl-adm.ARPA> TGMIKEY%CALSTATE.BITNET@wiscvm.wisc.EDU talks about two ways to read one character from the input without waiting for a carriage return. > >C provides you two functions for that : > > (1) x = getch(); where x is char x; This will return a character from the > keyboard (without echoing that character) and it does NOT require the > user to follow his/her input with a . > > (2) x = getche(); where x is as above and the difference between this one > and the above getch() is that the character will get echoed to the > user as soon as typed. The problem? These aren't standard C functions, they are TURBO C functions. And they don't do quite what Mike says. What they actually do is immediately fetch the next character from the STANDARD INPUT -- not the keyboard. To really read a character from the keyboard in Turbo C, use the DOS-BIOS system call bioskey: #include int getkey(void) /* read next character from KEYBOARD, no echo */ { return (unsigned char) bioskey(0); } int getkeye(void) /* getkey + echo character */ { unsigned char key = bioskey(0); putchar(key); return key; } The cast to "unsigned char" throws away the high byte of the integer bios key returns (information about shift keys and so on that can often be ignored) Alex