Having trouble with the converting of strings to doubles. I've tried using strtod, but that does the same thing. It seems like this should work just find but perhaps using strtok has something to do with it. data[i].calories is a double of course.
data[i].calories = atof(strtok(NULL, ","));
It seems to assign either a positive or negative really big number to calories (a double, which means it must be reading the value wrong.
Data Expected:
12cx7,23:55:00,->0.968900025,(this could also be a double),0,74,0,2,
What it instead actually gets:
12cx7,23:55:00,->-537691972,0,0,74,0,2,
EDIT:
IM AN IDIOT I WAS DISPLAYING IT AS AN INT PFFFFFFFFFFFFFFFF.
Assuming we have an input like this,
And we would like to,
That is we would like to separate the alphanumeric data . And then the remaining ints and floats, we would like to print in the correct format, I would do something like the following:
For the
isInteger()function, I took the idea/code from this accepted answer. The rest is quite original and probably could be refined/improved.This produces then this output:
which is basically the output that we want, except with the very important difference that the input was a whole single string and the output is doubles/floats, ints and strings correctly identified and printed with the correct formatting.
EDIT:
I am not any doing error-handling here. This code is just to give the OP a proof-of-concept. Check and control for any errors returned from the used
strtoXfunctions.