Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Tek) 9/26/83; site tekcad.UUCP Path: utzoo!linus!decvax!microsoft!fluke!ssc-vax!uw-beaver!tektronix!tekcad!franka From: franka@tekcad.UUCP Newsgroups: net.lang.c Subject: Re: 1-char input in C - (nf) Message-ID: <172@tekcad.UUCP> Date: Sun, 25-Dec-83 13:10:47 EST Article-I.D.: tekcad.172 Posted: Sun Dec 25 13:10:47 1983 Date-Received: Sun, 1-Jan-84 02:12:01 EST Sender: franka@tekcad.UUCP Organization: Tektronix, Beaverton OR Lines: 31 #R:ihuxn:-46300:tekcad:2600002:000:1170 tekcad!franka Dec 25 10:10:00 1983 >Your problem is a common one. The problem is that UNIX is buffering up >the data, as opposed to the C library routines. The most portable solution >(and easiest to understand) is to use the system() call to change the >tty mode as follows: > >#include >main() { > system("stty raw"); /* dont buffer data */ > getchar(); > system("stty -raw"); /* restore normal buffering */ >} > >The other option is to use ioctl() (or gtty & stty on systems that have it) >to set the tty modes properly. The problem with this is that BELL, BSD and >V7 systems are all different in the exact format of these ioctl()'s The other problem with this is that if somebody hits a ^C (or ^\) during the getchar, the terminal gets put in "raw" mode. This is very, very confusing to a novice user (I assume that is who you are writing for, with such a limited command set) who suddenly cannot backspace, use the return key on a command, etc. From the truly menacing, /- -\ but usually underestimated <-> and soon to be gone, Frank Adrian (tektronix!tekcad!franka)