Char to Float conversion
Is there a function that takes a char and changes it to a float?
Visit http://members.xoom.com/ivanickgames
Visit http://members.xoom.com/ivanickgames
Yep. Look for atof(const char* string)
example:
char* fltString = "1.4354";
float flt = atof(fltString);
Andrew
How would you reverse that? (float to string)
Is there a better way to record a float to a save file without using a structure? (I''m making a dynamically built save file)
E:cb woof!
Is there a better way to record a float to a save file without using a structure? (I''m making a dynamically built save file)
E:cb woof!
E:cb woof!
quote: Original post by dog135
How would you reverse that? (float to string)
I don''t think that there is a built in function for that. To do this I usually do something like:
char fltBuffer[80];
float flt = 1.2345;
sprintf(fltBuffer, "%f", flt);
This will place the value inside the buffer string. You can also tell how many decimal places to keep and stuff like that.
quote:
Is there a better way to record a float to a save file without using a structure? (I''m making a dynamically built save file)
E:cb woof!
I am not sure what you mean here. To save a float to a file I use:
FILE* fileStream = fopen("test", "wb");
float flt = 1.2345;
fwrite(&flt, sizeof(flt), 1, fileStream);
fclose(fileStream);
I don''t know if this is what you mean.
Andrew
Just a follow-up here after looking in the help.
There is a function that will convert a float to a string (at least under VC++ 5).
Try looking at the _ecvt() function. I haven''t used it personally but it may do the trick.
Andrew
There is a function that will convert a float to a string (at least under VC++ 5).
Try looking at the _ecvt() function. I haven''t used it personally but it may do the trick.
Andrew
Thanks for all your help.
Visit http://members.xoom.com/ivanickgames
Visit http://members.xoom.com/ivanickgames
Visit http://members.xoom.com/ivanickgames
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement