From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: printf/getch problem Date: Mon, 26 Jan 1998 10:05:49 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 38 Message-ID: <34CC51ED.7B2CF999@LSTM.Ruhr-UNI-Bochum.De> References: <34cc2c99 DOT 1842074 AT news DOT telusplanet DOT net> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk tg wrote: > > Whenever I have a printf before a getch, it waits until a key is > pressed before printing the string. However, if the string ends with a > \n it works fine. > > e.g printf("blah"); > getch(); > > will wait for a key to be pressed and then print "blah". If I replace > it with "blah\n" it works. > > Is this supposed to happen and if so how do I get around it? I've > tried the same thing with a borland compiler and it works as expected. Welcome to the world of UNIXy file buffering. If you had read the FAQ, you would have found that the solution is to fflush(stdout); if your string doesn't end with a newline. BTW, Eli, wouldn't it be better to leave out _which_ section to in the FAQ? Then people might at least take a longer glance at it and hopefully understand a few more things? And why the hell are you working on sundays? ;-) -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************