I am writing a function that will be passed a float in the form of a void pointer. What I am attempting to do, is convert that float into a string equivalent so that I might save that binary data in memory. For example, the call to my function is as follows:
void * f(void * data);
If a user passes me
float value = 3.14;
I would like to convert it into a string as shown below:
"3.14"
The approach that I think I should use, would be to first determine the number of values within the float: 3.14 = four values. I would then have to loop through each value and convert it to a character.
A couple problems I am having, is 1: I'm not sure if it is even possible to determine the number of values associated with a given float. 2: How would I convert each value into its string equivalent?
I came across itoa and sprintf. However, itoa isn't part of the standard C libary, and I am unsure as to whether or not sprintf will do as I desire.