www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/22/03:03:52

From: mambuhl AT tiac DOT net (Martin Ambuhl)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using getch() in DJGPP
Date: Mon, 21 Oct 1996 20:41:59 GMT
Organization: The Internet Access Company, Inc.
Lines: 53
Message-ID: <54gn7q$7mg@news-central.tiac.net>
References: <01bbbea6$206725e0$454fb7ce AT default>
NNTP-Posting-Host: 207.60.65.16
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"bitc" <uh AT rt> wrote in <01bbbea6$206725e0$454fb7ce AT default>
(comp.os.msdos.djgpp, 20 Oct 1996 16:45:02 GMT):

(posted & emailed)

:Why doesn't the following function in DJGPP...

:int main()
:{
:	printf("Hello.");
:	getch();
:}

(BTW, since getch() is not a standard function, you will find
implementations in which it behaves differently from your expectations
or is completely missing.)
The streams stdin and stdout are asynchronous in standard C,  This
means that there is no defined relationship between when output
appears on stdout and input is accepted on stdin.  To force the output
ro appear before the attempt to getch(), rewrite as

#include <stdio.h>
#include <conio.h>	
int main(void)
{
	printf("Hello");
	fflush(stdout);	/* <- note */
	getch();
	return 0;
}

:Now, in every other compiler I've seen, the binary will run like this:

(see the note above.  Many compilers wil vary in more than 1 way in
the way your code behaves).

:Hello. {keypress}{exit}

:But when compiled under DJGPP, I get this:

:{keypress}Hello. {exit}

:This isn't making sense to me. Why isn't the string printing until I press
:a key? Shouldn't the program run in the order I wrote the instructions?

:Jake Harvey
:jwharvey AT interaccess DOT com


Martin Ambuhl            mambuhl AT tiac DOT net
Honors Bridge Club, 115 E 57th, New York     
/* mha - @ripco.com, @ix.netcom.com, etc. inactive */

- Raw text -


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