Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!ut-emx!walt.cc.utexas.edu!ycy From: ycy@walt.cc.utexas.edu (Joseph Yip) Newsgroups: comp.lang.c Subject: Non-block read Message-ID: <24911@ut-emx.UUCP> Date: 22 Feb 90 18:17:19 GMT Sender: news@ut-emx.UUCP Reply-To: ycy@walt.cc.utexas.edu (Joseph Yip) Distribution: usa Organization: The University of Texas at Austin, Austin, Texas Lines: 34 I was trying to do some non-blocking read. I want to program read() so that what I asked for y/n answer, hitting y or n (without pressing return key) is enough. However, the program will wait for a return key to be read although I have made the read non-blocking. Any suggestions? How can I solve the problem? Thanks Joseph Yip ------------------------- #include #include #include main() { char lbuf[100]; int n; /* make non-blocking */ if ( (fcntl(0,F_SETFL,fcntl(0,F_GETFL,0) | FNDELAY) == -1) ) exit(-1); /* wait for a key keystroke */ while ( read(0,lbuf,80) == -1) ; /* set blocking read before exit */ if ( (fcntl(0,F_SETFL,fcntl(0,F_GETFL,0) & ~FNDELAY) == -1) ) exit(-1); }