www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/07/03:33:20

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Newbie Question: Why doesn't this work?
Date: Sat, 07 Dec 1996 01:39:40 -0800
Organization: Three pounds of chaos and a pinch of salt
Lines: 50
Message-ID: <32A93B5C.19C5@cs.com>
References: <19961206 DOT 232059 DOT 4631 DOT 0 DOT Praxis_Beta AT juno DOT com>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp211.cs.com
Mime-Version: 1.0
To: Bruce A Locke <praxis_beta AT juno DOT com>
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Bruce A Locke wrote:
> 
> The ClrScr() command seems to do nothing at all in the program despite
> INFO help stating that it clears the screen.  Also, even if I set the
> textcolor() and textbackground(), The existing screen attributes take
> priority over the colors I set.....
> 
> Does DJGPP handle CONIO differently than in other dos compilers, or am I
> in error?

Try using '-Wall' when you compile; it makes a world of difference when
trying to debug code.  I wish this were the default, because we keep
getting these kinds of questions from people graduating from Borland and
Turbo C.  Anyway...

> #include <conio.h>

You need to also include <pc.h> for the definition of getkey(), and
<stdio.h> for the definition of putchar().  This is caught by -Wall.

> void main(void)

This is a non-ANSI way to declare main().  main() MUST!!! return an int.

>         textcolor(15);
>         textbackground(0);
>         clrscr;

Here is where you would get another warning if you used '-Wall'. 
Specifically:

coniotst.c:26: warning: statement with no effect

What this means is that you should be using:
	clrscr();

Notice the difference?  FYI, the reason "clrscr;" by itself works is
because the name of a function without parentheses serves as a pointer
to that function, so that line is like typing "52;" or "x;" - it's
syntactically valid, but logically meaningless.

Everything else looks okay to me.  Try making these changes and see how
it works.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |        fighteer AT cs DOT com          |
| Proud owner of what might one   |   http://www.cs.com/fighteer    |
| day be a spectacular MUD...     | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------

- Raw text -


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