Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!usc!orion.oac.uci.edu!cerritos.edu!arizona.edu!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: getchar() Message-ID: <1038@caslon.cs.arizona.edu> Date: 5 Mar 91 20:11:07 GMT References: <1991Mar5.063644.8459@cs.mcgill.ca> Organization: U of Arizona CS Dept, Tucson Lines: 24 In article <1991Mar5.063644.8459@cs.mcgill.ca> storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: >[program that reads input using getchar() deleted] > > Echos every character that you put on the screen. However, it does not >stop (even after a Capital A) until you hit return. The problem with your program is that stdin (and stdout) is buffered. This means for input, that when you request a character, the system actually gets a whole line, and then feeds you the result one character at a time. This is efficient for when the overhead on a read is high, and doesn't depend much on the size of the input read. That is why your program doesn't quit until you hit return; the call to getchar() doesn't return until you hit (carriage) return. Your next question, no doubt is "how do I do unbuffered reads?". Unfortunately, there is no portable way to do this, although many (most?) systems have some way to do it. I would suggest you RTFM to find out more. -- Dave Schaumann dave@cs.arizona.edu 'Dog Gang'! Where do they get off calling us the 'Dog Gang'? I'm beginning to think the party's over. I'm beginning to think maybe we don't need a dog. Or maybe we need a *new* dog. Or maybe we need a *cat*! - Amazing Stories