From: "Ilya P. Ryzhenkov" 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 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Mr David Potts wrote: > #include > #include > 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