Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!bellcore!faline!ulysses!mhuxt!ihnp4!homxb!mtuxo!mtune!codas!killer!toma From: toma@killer.UUCP (Tom Armistead) Newsgroups: comp.lang.c Subject: Re: HELP!! Message-ID: <2015@killer.UUCP> Date: Sat, 7-Nov-87 00:25:47 EST Article-I.D.: killer.2015 Posted: Sat Nov 7 00:25:47 1987 Date-Received: Wed, 11-Nov-87 04:04:41 EST References: <10202@brl-adm.ARPA> Organization: The Org. for the Disorg. of Org. Lines: 91 Summary: How to do single character I/O from stdin/stdout In article <10202@brl-adm.ARPA>, jl3j+@andrew.cmu.EDU (John Robert Leavitt) writes: . . . > The situation is this. We need a way of getting one character from > stdin without having to hit return. That's it. (For the CMU folks getting > this, we are using Andrew and RT workstations. I think you guys are the ones > who will be most able to help.) However, we cannot find a way top do this. > ANY suggestions would be appreciated. . . . real quick and dirty, this will do it for you under System V and maybe others... --------- main() { char ch; system("stty raw -echo"); /* your system may require '-cooked' */ /* instead of 'raw' */ /* ** now all io to terminal will be 'raw', i.e. single character i/o ** getchar() will work just fine... */ system("stty -raw echo"); /* again, you may need 'cooked' instead */ /* of '-raw' */ } -------- This could be done more elegently by a call to gtty() and stty() or ioctl() like this... -------- #include main() { struct sgttyb argp,argsav; int ch; /* ** get current terminal characteristics ** for stdin */ gtty(0,&argp); /* ** save current setup */ memcpy(&argsav,&argp,sizeof(struct sgttyb)); /* ** set flags to turn off echo and ** character buffering (binary mode) */ argp.sg_flags |= RAW; /* no buffering */ argp.sg_flags &= ~ECHO; /* and turn off echo */ /* ** now set the terminal as sepcified ** by those flags */ stty(0,&argp); /* ** now standard character reads will work ** without any buffering */ while ((ch = getchar()) != 'q') printf("->%c<-",ch); /* ** reset back to original terminal charactistics */ stty(0,&argsav); } ---------- maybe this will help??? Tom --- -- ------------- Tom Armistead UUCP: ...!ihnp4!killer!toma