From: "Mr. Lin" Newsgroups: comp.os.msdos.djgpp Subject: Re: printf/getch problem Date: Mon, 26 Jan 1998 22:25:54 +0800 Organization: TMnet Malaysia Lines: 35 Message-ID: <6ai65c$m0l$1@news.tm.net.my> References: <34cc2c99 DOT 1842074 AT news DOT telusplanet DOT net> NNTP-Posting-Host: tsk-35-245.tm.net.my To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk tg wrote in message <34cc2c99 DOT 1842074 AT news DOT telusplanet DOT net>... > 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. > The output in your printf statement was actually buffered (In DJGPP) When you use a new line '\n' , the buffer was actually flushed. If no new line character was used , the output is buffered while getch() was executed. To force a flush (if you don't want to use '\n') , use fflush(stdout) Hence , printf("blah"); fflush(stdout); getch(); Should work. Regards, Kean