Xref: news2.mv.net comp.os.msdos.djgpp:3051 From: alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de (Alexander Lehmann) Newsgroups: comp.os.msdos.djgpp Subject: Re: Odd printf behaviour Date: 23 Apr 1996 22:22:27 GMT Organization: Technische Hochschule Darmstadt Lines: 35 Message-ID: <4ljl73$1ep4@rs18.hrz.th-darmstadt.de> References: <4ljetk$bvh AT sulawesi DOT lerc DOT nasa DOT gov> NNTP-Posting-Host: hp62.rbg.informatik.th-darmstadt.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Gregory Fedor (gfedor AT lerc DOT nasa DOT gov) wrote: : I wrote some simple code that utilizes the gotoxy() and printf() : statements to place text on the screen, ala: : while(!done) : { : gotoxy(column, line); : printf(" %... ", ...); : // update column : // update line : } : When I run this type of code nothing appears on the screen. I can see : the cursor jumping around, but nothing else. However, if I include a : '\n' in the printf statement, things display fine, *or* as soon as I : printf with a '\n' outside the loop, then **all** the text gets : displayed. It's almost as if it's being buffered, and isn't displayed : until a '\n' comes along. This is because the stdout stream is line buffered by default. So the output is flushed when the buffer is full (1024 chars or something) or if a \n is printed. To flush the buffer explicitly, you can use the fflush function. Another possibility is to set stdout to non-buffered mode, but this way the output becomes slower (since it is done char-by-char), so the first solution is usually favorable. bye, Alexander -- Alexander Lehmann, | "On the Internet, alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de (plain) | you're a dog."