Sender: nate AT cartsys DOT com Message-ID: <3606DD51.AA4FB7E@cartsys.com> Date: Mon, 21 Sep 1998 16:12:17 -0700 From: Nate Eldredge MIME-Version: 1.0 To: Uhfgood CC: djgpp AT delorie DOT com Subject: Re: Simple C question probably having to do with DJGPP References: <19980920183653 DOT 24923 DOT 00002490 AT ng126 DOT aol DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Uhfgood wrote: > > Well here's is the simple question. consider the following code : > > printf("This demonstrates a \\a escape sequence: \a"); > getch(); > > Now answer me this, how come it waits until a key is pressed to display the > string? > > Now please I already know two ways to make it work like I think it's supposed > to. > one is to put a \n after the last part of the screen, and the other is to type > "fflush(stdout);" but that still doesn't answer my basic question. Please just > explain it to me? Also if you don't want to bother with this message after you > read it just close it, instead of wasting your time writing me back a flame. > (I'm not trying to be mean about, I just mean I figure it would take more > effort to flame me than it would to either ignore the question, or tell me the > answer).. Firstly, did you read the FAQ? The reason is buffering. In DJGPP, file I/O requires a call to DOS, which requires a switch to real mode. All this is rather slow. Therefore, I/O is buffered, which means the library accumulates a larger chunk of data before writing it, which decreases this overhead. The `stdout' stream by default uses line buffering, which means the data is not written until a newline character ('\n') is output. This yields a large performance advantage especially in cases where data is being written one character at a time (with `putc', for instance). Thus, when you print a newline, the data is actually written to the device (the console, in this case). `fflush' is provided to get around this buffering; it has the effect of immediately flushing the buffer of that stream and writing its data immediately. With `setvbuf', you can change the buffering parameters of streams. -- Nate Eldredge nate AT cartsys DOT com