🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #34117

Re: problem with mwc atoi(), version 2.0.1

#34117
From: joe smith
Date: Sat, 17 Sep 1988 03:13
25 lines
1815 bytes
In article <12562@ncoast.UUCP> btb@ncoast.UUCP (Brad Banko) writes:
>		printf("%d %d %s %d %d %d\n",
>			x, i, argv[i], (double) x / MAXVAL, atoi(argv[i]),
>			(double) x / MAXVAL * atoi(argv[i]) + 1);

The way printf picks up arguments is as follows:
%d = Pick up 2 bytes of x (which is an int) = OK
%d = Pick up 2 bytes of i (which is an int) = OK
%s = Pick up a pointer to a string argv[i] = OK
%d = Pick up 2 bytes of the 8 bytes that correspond to the value of the
     expressiion "(double) x /MAXVAL".
%d = Pick up the next 2 bytes from the previous double-precision value
%d = Pick up the 4th and 5th bytes of the double-precision value
\n = Start a new line (which ignores the 7th and 8th bytes of the first
     double precision result, and ignore the 2 bytes of the atoi value,
     and ignore the 8 bytes of the 2nd double-precision floating point value.

The problem is in the use of %d with double.  You should be using %f
for double, however you don't need double in this program; use ints and
longs instead.
-- 
+----------------------------------------------------------------------------+
| TYMNET:JMS@F29  CA:"POPJ P,"  UUCP:{ames|pyramid}oliveb!tymix!antares!jms  |
| INTERNET:JMS%F29.Tymnet@Office-1.ARPA   PHONE:Joe Smith @ (408)922-6220    |
+----------------------------------------------------------------------------+
Technical Details
Message-ID: <157@antares.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!oliveb!tymix!antares!jms
References: <12562@ncoast.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ames!oliveb!tymix!antares!jms
From: jms@antares.UUCP (joe smith)
Newsgroups: comp.sys.atari.st
Subject: Re: problem with mwc atoi(), version 2.0.1
Keywords: Never use %d on a double
Message-ID: <157@antares.UUCP>
Date: 17 Sep 88 03:13:14 GMT
References: <12562@ncoast.UUCP>
Reply-To: jms@antares.UUCP (joe smith)
Organization: Tymnet QSATS, San Jose CA
Lines: 24