www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/02/20:07:45

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf() and shl Questions
Date: Sun, 29 Jun 1997 19:53:33 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 29
Message-ID: <33B6BD3D.3622@cs.com>
References: <33B59082 DOT F71 AT sandiegoca DOT ncr DOT com>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Justin Talbot wrote:
> 
> Two problems:
> 
> First if I compile and run a simple program:
> void main(void)

That is incorrect.  main() must return an integer according to the ANSI
standard.  Declaring it as void may cause undefined behavior.

> {
>         printf("Hello world");
>         getch();
> }

stdio and conio functions use the screen and console differently. 
stdout is line-buffered, so you don't see anything on the screen until
you 1) print a newline, 2) call fflush( stdout ), 3) use a stdio input
function, 4) the internal buffer overflows.

Since getch() is a conio function, it does not invoke rule 3.

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Money is truthful.  If a man speaks |
|       aka Fighteer I       | of his honor, make him pay cash."    |
|   mailto:fighteer AT cs DOT com   |                                      |
| http://www.cs.com/fighteer |               - Lazarus Long         |
---------------------------------------------------------------------

- Raw text -


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