www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/27/04:59:19

From: "Ilya P. Ryzhenkov" <ilya AT spy DOT isp DOT nsc DOT ru>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Simple Getch problem
Date: Wed, 27 Nov 1996 14:14:03 -0800
Organization: Institute of Semiconductor Physics
Lines: 24
Distribution: world
Message-ID: <329CBD2B.6301@spy.isp.nsc.ru>
References: <5783b1$gbk AT yama DOT mcc DOT ac DOT uk>
Reply-To: ilya AT spy DOT isp DOT nsc DOT ru
NNTP-Posting-Host: arab.isp.nsc.ru
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Mr David Potts wrote:
> #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?
The cause is file buffering. As printf(...) is somewhat like
fprintf(stdout,...), output is buffered and you need fflush(stdout) 
after printf to force text to appear. Buffer is automaticaly flushed 
after printing '\n' and before program exits. So use either
 printf("Before getch\n"); or printf("Before getch"); fflush(stdout);


-- 
							Sincerely yours, Ilya
-----------------------------------------------------------------------------
mailto://ilya AT spy DOT isp DOT nsc DOT ru                           
http://spy.isp.nsc.ru

- Raw text -


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