www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/31/16:03:41

Xref: news2.mv.net comp.os.msdos.djgpp:8107
From: terra AT diku DOT dk (Morten Welinder)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Scanf doesn't work -- sure it does
Date: 31 Aug 1996 15:25:50 GMT
Organization: Department of Computer Science, U of Copenhagen
Lines: 25
Sender: terra AT tyr DOT diku DOT dk
Message-ID: <509lhu$1t0@vidar.diku.dk>
References: <01bb974a$24b5f820$24c5b7c7 AT platko DOT ix DOT netcom DOT com>
NNTP-Posting-Host: tyr.diku.dk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"Bob Platko" <platko AT ix DOT netcom DOT com> writes:

>My code works fine in Borland, but not in DJGPP!  What's wrong?

Your program.

If you compile your program with "gcc -Wall -O2 -c foo.c" you will
see

  foo.c: In function `main':
  foo.c:16: warning: unsigned int format, different type arg (arg 2)
  foo.c:18: warning: unsigned int format, different type arg (arg 2)
  foo.c:48: warning: implicit declaration of function `getch'

So you are passing a pointer to the wrong kind of object to scanf().
Therefore scanf() overwrites memory you did not mean to.

Nuke the "short" and you will have a correct program.

Morten


PS: There are some problems with scanf() if I remember things
    right.  They have to do with the return value and are being
    worked on or have already been solved for the next release.

- Raw text -


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