delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/20/21:42:00

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using getch() in DJGPP
Date: Sun, 20 Oct 1996 20:34:25 -0700
Organization: Three pounds of chaos and a pinch of salt
Lines: 43
Message-ID: <326AEF41.3C69@cs.com>
References: <01bbbea6$206725e0$454fb7ce AT default>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp103.cs.com
Mime-Version: 1.0
To: bitc <uh AT rt>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'd like to add to what everybody else said on the subject that it's
generally a bad idea to mix stdio functions with conio functions.  stdio
functions (printf, puts, scanf, getchar) are line-buffered and use DOS
read/write commands, while conio functions (cprintf, cputs, cscanf,
getch) use direct writes to video memory and read directly from the BIOS
keyboard.  So when you use printf() and getch() together, you are in
essence mixing apples and oranges, with potentially harmful results no
matter how careful you are.

My recommended solution to your problem:

#include <stdio.h>

int main( void )
{
    printf( "Hello." );
    getchar( );  /* this flushes stdout automatically so you don't
		    need fflush() or a newline */
    return 0;
}


------- OR -------

#include <stdio.h>
#include <conio.h>

int main( void )
{
    cprintf( "Hello." );
    getch( );
    return 0;
}

-- 
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------

- Raw text -


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