From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: [Q] Bug with printf? Date: Wed, 13 Aug 1997 19:50:13 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 43 Message-ID: <33F20FF5.631E@cs.com> References: <5ss8me$25j$1 AT kurica DOT wt DOT com DOT au> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp217.cs.com 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 Robert Debeljakovic wrote: > > Hi all, > I just started writing some test programs and I came across something... > If you use printf without a newline character in the string, it does print the > test to the screen.... > > eg: > printf("hello\n"); gives me > hello > > where as printf("hello"); gives me > [nothing] This is one of the more commonly asked DJGPP questions. :) By default, standard output in DJGPP is line-buffered. The buffer is flushed when any of the following occur: - You print a newline character ('\n'). - You flush the stdout buffer with fflush(). - You call an input function which reads from stdin: getchar(), scanf(), gets(), etc. - You overflow the internal stdout buffer. - You disable buffering with a call to setbuf() or setvbuf(). One other bit of information: it is a bad idea to mix stdio functions with conio functions when requesting input from users. While stdout is buffered and goes through the DOS file handling functions, conio writes directly to video memory and reads directly from the BIOS keyboard interrupt. If you do plan to use conio to get input (single or extended keystrokes, for instance), you should either use conio output functions or make sure to flush the buffer before reading input or clearing the screen. hth! -- --------------------------------------------------------------------- | John M. Aldrich |"A competent and self-confident person| | aka Fighteer I | is incapable of jealousy in anything.| | mailto:fighteer AT cs DOT com | Jealousy is invariably a symptom of | | http://www.cs.com/fighteer | neurotic insecurity." - Lazarus Long| ---------------------------------------------------------------------