Hi, I'm working for first time with arduino, and I want to convert the numbers stored in a char array. I been reading that I need to use the "atof" instruction, but I won´t be able to make my code to run correctly.
I'm reading data from a GPS receiver, and I want to manipulate that data like float or int variables.Here's an example:
TimeBuffer will only contain indexes 0 through 8, so if j is anything but zero you are clobbering things. Also, you need a '\0' in the last place to signal atof() as to the end of the string.
Why not atof(linea)? (Assuming there is a '\0' to terminate it.)
char timeBuffer[6]; // donde, para este caso, indices[0]=5 e indices[1]=15, entonces el ciclo lee desde linea[6] hasta linea[14]
timeBuffer[0]=linea[j+1]; //2
timeBuffer[1]=linea[j+2]; //1
timeBuffer[2]=linea[j+3]; //1
timeBuffer[3]=linea[j+4]; //6
timeBuffer[4]=linea[j+5]; //0
timeBuffer[5]=linea[j+6]; //5
timeBuffer[6]=linea[j+7]; //.
timeBuffer[7]=linea[j+8]; //0
timeBuffer[8]=linea[j+9]; //0
You have 6 bytes in timeBuffer but are writing to the 9th.