Mail Archives: djgpp/1997/04/17/21:17:56
Fred Smith wrote:
>
> J.D. Piette (pjames AT lynx DOT dac DOT neu DOT edu) wrote:
> : Hi,
>
> : I recently downloaded DJGPP(the GCC2721 version) and RHIDE v1.2 and got
> : everything set up and running fine. BTW I think the program is
> : wonderful and I am thoroughly enjoying using it.
>
> Great!
>
> : My problem is that when I call the function atof(), it returns a value
> : of 1.00. Here is the code segment.
>
> : char buffer[80];
> : double price;
> : ....
> : ....
> : printf("\n\nCurrent Price?");
> : gets(buffer);
> : if(buffer[0]!='\0')
> : {
> : price=atof(buffer);
> : }
>
> : price always has a value of 1.00. I looked at it in the debugger and
> : buffer has the correct value and if I use atoi() the correct number is
> : assigned to price(the integer value). Any information as to why this is
> : happening would be greatly appreciated. Please reply by e-mail.
>
> I don't see a declaration of atof() (or more correctly an include that
> contains the declaration) here anywhere. Most likely the compiler does not
> see one either, so it ASSUMES that atof returns an int.
>
> You've got to make sure to include the correct headers! In this case it
> should be stdlib.h.
>
Yeh! If you're not carefull to use prototypes / headers correctly that
can be a
real trap. I spent one (not so) memorable late night / early morning a
tracking
down a very similar problem to the one described. Once you figure out
what is
hapening, it's *obvious* D'oH !
Later SG
--
Steve Gibson
ADI Limited, CCIS Systems Group
Email: gibson AT ccis DOT adisys DOT com DOT au
Snail: 22 Stirling Hwy
Nedlands
Western Australia
Nbrs : (tel) +61 9 333 8917 (fax) +61 9 333 8889
- Raw text -