Freading floats instead of numbers

Posted by Marowi on Fri 19 Mar 2004 04:38 PM — 9 posts, 27,798 views.

#0
I am saving pop_support of a province as a (%.1f) float. If I set the pop_support to 66.574, it gets saved as 66.6.
("PopSupport 66.6") This is fine. When I reboot the mud, I get a message during startup saying "BUG: Fread_province: no match: .6". I've traced this to a part of the code that says:

case 'P':
KEY( "PopSupport", province->pop_support, fread_number( fp ) );
break;

It then displays the pop_support as being 66.0, because it doesn't load the additional '.6' and reports it as a bug.

I tried changing 'fread_number' to 'fread_float' and then got a compile report saying 'implicit declaration of function 'fread_float'.

I'm all out of ideas, so please help!
Canada #1
The problem is that fread_float does not exist in the code. However, very recently myself and Samson had this exact same discussion, and we both developed a fread_float. You can simple copy one of them, paste it in db.c with the other freads, add the prototype to mud.h, and you should be good to go. The link to those functions is here:

http://forums.alsherok.net/index.php?showtopic=597
#2
Ok, new problem. I tried the "atof(fread_string_noalloc(fp))" and it reads the float in correctly, but not the "GovernedBy" on the next line.
Canada #3
Yeah, that method == BAD, unless you rewrite all your files to save ~ after each line. Did fread_string_noalloc actually work? I didn't think that was stock. It would be better to copy either of the functions and use one of them.
USA #4
fread_string_noalloc is not a stock function and should have complained unless you've had someone modify your code to contain it.
#5
Ok, so.. where do I implement that snippet on Samson's forums? Randomly sticking it in doesn't work (I tried >.<)
Canada #6
How it it not working? Either function can just be dropped in anywhere(most appropriate place would be db.c with the other fread_* functions). Copy and paste, and add the prototype to mud.h with the other fread_* prototypes, and you should be all good.
#7
Forgive the stupidity... I forgot to add it to mud.h

Works like a charm now, thanks.
USA #8
Hey, I'd just like to say thanks to Gavin, Greven, and Samson for the fread_float. I long ago fixed the reading of PopSupport in a different way but I quickly changed to these. It seemed like a better solution, plus now I have the fread_float function for when I save other floats. Thanks.