Mail Archives: djgpp/1996/11/24/18:52:17
Mr David Potts (mfepsdp AT hero DOT mcc DOT ac DOT uk) wrote:
> ... found the following odd behavior.
>
> #include<stdio.h>
> #include<conio.h>
> int main(void)
> {
> printf("Before getch");
> getch();
> return(0);
> }
> But when I ran it, it waited for a key press *then* printed
> the text rather than the other way round. What is going on?
Nothing the least bit odd here. Printf is part of the stdio package
which provides BUFFERED I/O. As such there is nothing in your program to
force the buffering mechanism to flush the buffered data to the output
device (i.e., the screen).
Try adding:
fflush (stdout);
before the getch().
Fred
--
-------------------------------------------------------------------------------
.---- Fred Smith / Office: fred AT computrition DOT com
( /__ ,__. __ __ / __ : / 508-663-2524
/ / / /__) / / /__) .+' Home: fredex AT fcshome DOT stoneham DOT ma DOT us
/ / (__ (___ (__(_ (___ / :__ 617-438-5471
-------------------------------- Jude 1:24,25 ---------------------------------
- Raw text -