🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #42663

Re: scanf problem in TC v2.01.

#42663
From: Tom Almy
Date: Mon, 19 Feb 1990 16:33
33 lines
1464 bytes
In article <204@sdscal.UUCP> keith@sdscal.UUCP (Keith Jones) writes:

>Well, I didn't quite believe it, but I made this test file and sure enough,
>the printf doesn't print out anything that even looks like it approximates
>PI.
>main()
>{
>    float f;
>    char *string = "3.1415926";
>    f = atof( string );
>    printf( "pi = %f\n", f );
>}

The "problem" is that C, in its infinite stupidity about data types, assumes
that all functions return ints, unless you declare otherwise. So the nice
atof() function, which returns a double, is treated in main() like it has
returned an int, which promptly gets converted into a meaningless float value
that is printed.

If you add the declaration:

double atof();

or, even better:

double atof(const char *string);

or include either stdlib.h or math.h, the program will run successfully.


Tom Almy
toma@tekgvs.labs.tek.com
Standard Disclaimers Apply
Technical Details
Message-ID: <6890@tekgvs.LABS.TEK.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!zephyr.ens.tek.com!tekcrl!tekgvs!toma
References: <7192.25d1e107@dit.ie> <25D4D935.3073@maccs.dcss.mcmaster.ca> <25D8649A.24584@maccs.dcss.mcmaster.ca> <204@sdscal.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!zephyr.ens.tek.com!tekcrl!tekgvs!toma
From: toma@tekgvs.LABS.TEK.COM (Tom Almy)
Newsgroups: comp.sys.ibm.pc
Subject: Re: scanf problem in TC v2.01.
Message-ID: <6890@tekgvs.LABS.TEK.COM>
Date: 19 Feb 90 16:33:50 GMT
References: <7192.25d1e107@dit.ie> <25D4D935.3073@maccs.dcss.mcmaster.ca> <25D8649A.24584@maccs.dcss.mcmaster.ca> <204@sdscal.UUCP>
Reply-To: toma@tekgvs.LABS.TEK.COM (Tom Almy)
Organization: Tektronix, Inc., Beaverton,  OR.
Lines: 33