www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/12/05:09:19

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: (possible) printf bug
Date: Sun, 08 Dec 1996 22:07:35 -0800
Organization: Three pounds of chaos and a pinch of salt
Lines: 34
Message-ID: <32ABACA7.2C70@cs.com>
References: <01bbe56f$dd5b4f60$666fd9ce AT scully>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
To: Cephaler <scully AT ix DOT netcom DOT com>
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Cephaler wrote:
> 
> printf("Loading prefs...");
> ....
> window(1,1,80,4);
> cprintf("Choose an option:\n\r1) start\n\r2) load\n\r3) quit\n\r? ");
> fscanf(" %d", &choice);

Under DJGPP, stdout is line buffered, so anything you write with
printf(), puts(), putchar(), etc, will not show up until one of the
following occurs:

 - You print a newline to stdout.
 - You flush stdout.
 - You invoke an input function which reads from stdin.
 - You overflow the internal stdout buffer.
 - You issue a sync() or other command which affects all open files.
 - Your program exits.

In your program, you are mixing <stdio.h> functions with <conio.h>
functions, which always leads to trouble.  For example, if somebody were
to redirect the stdout of your program with "prog >prog.out", "Loading
prefs..." would be written to prog.out, and the rest of the text would
show up on the screen.  Very bad behavior.

In short, if you're going to use <conio.h> in a program, all its input
and output should be done using <conio.h> functions.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
| Plan:  To find ANYONE willing to |   http://www.cs.com/fighteer   |
| play Descent 2 on DWANGO!        | Tagline: <this space for rent> |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019