www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/24/18:52:17

Newsgroups: comp.os.msdos.djgpp
From: fredex AT fcshome DOT stoneham DOT ma DOT us
Subject: Re: Simple Getch problem
Organization: Absolutely None!
Message-ID: <E1DL3B.1oI@fcshome.stoneham.ma.us>
References: <5783b1$gbk AT yama DOT mcc DOT ac DOT uk>
Date: Sun, 24 Nov 1996 12:52:21 GMT
Lines: 55
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019