I have been trying to parse a stream of serial data that looks like this (i think it is spaced by tabs). I want to end up with an array of floats.
-1.1251 41.29 -0.03 0.00 0.0000 0.0 0.0 0 0.0 0.00 0.99 0.00 0.00 1
-1.1251 41.29 -0.03 0.00 0.0000 0.0 0.0 0 0.0 0.00 0.99 0.00 0.00 1
-1.1251 41.29 -0.03 0.00 0.0000 0.0 0.0 0 0.0 0.00 0.99 0.00 0.00 1
-1.1251 41.28 -0.03 0.00 0.0000 0.0 0.0 0 0.0 0.00 0.99 0.00 0.00 1
I have tried a few different approaches but I am not getting it to work. I made a loop that seems like it should do the job but it just does weird things to my code. please help.
void convertToFloatArray() {
if (newData == true) {
int p = 0;
int j = 0;
int k = 0;
char tokenPtr[] = {0};
float tokenFlPtr;
while( i <= 68 ) {
if (receivedChars[p] == ' '){
tokenFlPtr = atof(tokenPtr);
floatOutput[k] = tokenFlPtr;
p++;
j = 0;
k++;
}
else {
tokenPtr[j] = receivedChars[p];
p++;
j++;
}
}
}
}