Converting string to floating point array

Hello all

yep im new to this world of arduino and programming, ive encountered a problem in a project im working on with arduino UNO. I dont know if this is an easy problem but i want to convert text into a floating point array, inorder to be accessed as numbers instead of strings.

for example I can print this line of text as a string but i want to use it as a floating point array

from this: uint8_t x1 = '4.684E+000,1.000E+000'
to this: float x2 = {4.684E+000,1.000E+000}

Is there some easy way to achieve this?

thankyou in advance

Should be something like this

float x2[] = {4.684E+000,1.000E+000}

uint8_t x1 = '4.684E+000,1.000E+000'

Apart from the missing semicolon, that is perfectly legal C and will compile, but it isn't a string.
A string would need double quotes, but you couldn't assign it to a single byte.char x1 [] = "4.684E+000,1.000E+000";

Converting a string (with double quotes) to an array of floats requires two steps. First, you need to extract the tokens from the string (a token is a collection of characters that has some meaning). Since your string has values separated by commas, it can be parsed using strtok().

Once you have a token, you need to convert that string to a value, using atof().

Hi thanks everyone for your help! :slight_smile:

the atof() function worked perfectly to change the char variable to a float

thanks again