delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/30/05:12:44

Message-ID: <19970630091100.1690.rocketmail@send1.rocketmail.com>
Date: Mon, 30 Jun 1997 02:11:00 -0700 (PDT)
From: Jeffery Guan <djgpp AT rocketmail DOT com>
Subject: Re: printf() and shl Questions
To: djgpp AT delorie DOT com
MIME-Version: 1.0

---Justin Talbot <stevetalbot AT sandiegoca DOT ncr DOT com> wrote:
>
> Two problems:
> 
> First if I compile and run a simple program:
> void main(void)
> {
> 	printf("Hello world");
> 	getch();
> }
> The computer waits for me to press a key, then prints "Hello world",
> then ends.  The compiler esentially switches the two function calls. 
> This also happens if I place two getch()s after the printf()
statement,
> except it waits for two key presses before printing "Hello world."
> 
> Am I doing something very wrong? Is this a known problem with the
> compiler? Or is this something wrong with my copy?
> 

You could always use setvbuf to flush out the stdout.
eg....

void main(void)
 {
        setvbuf(stdout, NULL, _IONBF, 0);
 	printf("Hello world");
 	getch();
 }

instead of ...

void main(void)
 {
printf("Hello world");        
 	flush();
 	getch();
 }

where you have to flush each time you use the printf function. (kinda
silly)


_____________________________________________________________________
Sent by RocketMail. Get your free e-mail at http://www.rocketmail.com

- Raw text -


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