Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!columbia!cunixc!cunixd.cc.columbia.edu!gm From: gm@cunixd.cc.columbia.edu (Gary Mathews) Newsgroups: comp.lang.c Subject: getting a key from stdin in UNIX Summary: getchar Message-ID: <2802@cunixc.cc.columbia.edu> Date: 4 Feb 90 19:56:31 GMT Sender: news@cunixc.cc.columbia.edu Reply-To: gm@cunixd.cc.columbia.edu (Gary Mathews) Organization: Columbia University Lines: 25 I want to be able to press a key and respond to that key without pressing the key, such as getc on TurboC... If I use the curses library the getch command works fine under cbreak mode, but I want to use it without using an entire library for one command. the macro for getc in stdio.h is as follows: #define getc(p) --(p)->_cnt>=0? ((int)*(p)->_ptr++):_filbuf(p)) I've used variations of getc and the following, but I can't seem to get the optimum results... fgets(s1, 1, stdin); c = fread(&buf, sizeof(char), 1, stdin); scanf("%c", c); c = read(0, buf, sizeof(char)); How do you get a key without pressing enter? Does anyone have a solution for this? ------------------------------------------------------------------------------- Gary Jason Mathews | gm@cunixd.cc.columbia.edu Columbia University | Death is life's way of telling you you've been fired. ------------------------+ CPU time flies when you have a lot of bugs