Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!bria!mike From: mike@bria.AIX (Michael Stefanik) Newsgroups: comp.lang.c Subject: Re: getting input from keyboard Message-ID: <296@bria.AIX> Date: 31 Dec 90 18:22:16 GMT References: Distribution: comp.lang.c Organization: Briareus Corporation, Los Angeles, CA Lines: 35 In article , davidd@wolf.cs.washington.edu (David Doll) writes: > Hello, > Inside of some "C" code, I want to be able to get a single char(or > number) from the user without them having to type a carriage return. I'm assuming that you have the termio stuff, but here is a little ditty to get a single character from the keyboard: #include #include int getch() { struct termio old, new; char c; int ret; ioctl(0,TCGETA,&old); memcpy(&new,&old,sizeof(struct termio)); new.c_lflag &= ~ICANON; new.c_lflag &= ~ECHO; new.c_cc[VMIN] = 1; new.c_cc[VTIME] = 0; ioctl(0,TCSETA,&new); if ( read(0,&c,1) != 1 ) ret = EOF; else ret = (int)c; ioctl(0,TCSETA,&old); return(ret); } ----------------------------------------------------------------------------- Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation UUCP: ...!uunet!bria!mike "If it was hard to code, it should be harder to use!"