Solved
strtok and StrTo Float problems
Posted on 2003-02-18
First post - I program for fun only. Sorry if not a perfect question. I'll give you all 75 points for solution that works.
Short question:
How can I parse a char* twice?
Here's a better description:
When reading a comma separated text file which contains a decimal value (such as 456.12345), the StrToFloat function returns the "incorrect" value (it is not exact). I know this is is because of the rounding (althought not really rounding) issue with StrToFloat and atof.
My solution (that I can't get to work) is to parse the number string into two parts, the integer and the decimal. Then convert the integer portion to an integer. Take the decimal, truncate it at say 6 characters and convert it to a float (rounding it to 1 if necessary). Divide it by 1000000 and add the int to it.
The cause of the problem (I think) is nesting strtok functions.
I get the numberstring by parsing on a "," I want to take that char* and parse it again into two other strings.
Full code available upon request.
Thanks in advance.