Convert string to float

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:

char linea[9];
float time;

where, I know the data stored is:

linea[0]=2;
linea[1]=1;
linea[2]=1;
linea[3]=6;
linea[4]=0;
linea[5]=5;
linea[6]=.;
linea[7]=0;
linea[8]=0;

So, i decided to do the next conversion (j is a variable from a FOR loop):

char timeBuffer[9];
timeBuffer[0]=linea[j+1];
timeBuffer[1]=linea[j+2];
timeBuffer[2]=linea[j+3];
timeBuffer[3]=linea[j+4];
timeBuffer[4]=linea[j+5];
timeBuffer[5]=linea[j+6];
timeBuffer[6]=linea[j+7];
timeBuffer[7]=linea[j+8];
timeBuffer[8]=linea[j+9];
time=atof(timeBuffer);
Serial.print(time);

But, when i print the variable "time", i obtain something like these:

251605.00.05160500.00160500.00060500.00000500.00000000

It's possible to do this conversion?
what else can i do to make my code works?

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.)

What about dtostrf() ?

He is trying to parse a string into a float - the opposite of what dtostrf() does.

Edit: sorry I completely misunderstood...

Not according to his actual results, which are in line with his arrays being characters.

I think he needs to post all his code.

Thankyou for replying guys. I tried to post my previous code, but it's too large and full of comments to post it here.

Make it an attachment as a .txt file

Here’s the code.

gps.txt (10.1 KB)

This is no good:

            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.

I suggest strtok to break up the incoming string, and then atof for the floats.