converting String to float

i'm reading this data form Sdcard
14-11-2012|15:19:12:|29.30
14-11-2012|15:19:14:|28.81
14-11-2012|15:19:16:|29.30
14-11-2012|15:19:18:|29.30

How can i convert the time and the temperature form String to float since i will use them for
making a graph?

How do you plan on representing a time as a float value?

i need only hh and min ,for exapmle i can do :hh,(min/60)

I repeat - how do you plan on representing that as a float? Number of minutes since midnight (3:30AM would be 210)? Number of (fractional) hours since midnight (3:30AM would be 3.5)? What?

Number of (fractional) hours

Well, first you want to have the data as a "char *" not a "String".

Then, you can use the "atoi()" and "atof()" functions to extract the data you want.

char *data = "14-11-2012|15:19:12:|29.30";

int h = atoi(data+11);
int m = atoi(data+15);
float time = h + (m/100.0);
float temp = atof(data+21);

ok,thanks
but in my programme i already read from the file Srings,so now i have Srings and i want to convert them to Float.
i don't know if you mean that i need to convert first from String to char and after to float ??

pedro2012:
ok,thanks
but in my programme i already read from the file Srings,so now i have Srings and i want to convert them to Float.
i don't know if you mean that i need to convert first from String to char and after to float ??

If you are using the "String" from the library, you can convert that to char with toCharArray() - Arduino Reference otherwise you are just calling string a char array :slight_smile:

:slight_smile: i'm using Strings,
i didn't find examples for "toCharArray" :roll_eyes:

pedro2012:
:slight_smile: i'm using Strings,
i didn't find examples for "toCharArray" :roll_eyes:

char buf[40]; // 40 is one more than the maximum number of characters we will be able to work with.

incomingData.toCharArray(buf,40);

thank you very much for all of you