Compose number with other numbers from char to float

I have seen some solutions in internet but I can't found solution to my problem.

I have it: char c[50]; and I would like memory in a float variable, for example float f; the number inside of C variable. for example, I have it in c variable

c[20]=5
c[21]=0
c[22]=.
c[23]=2
c[24]=3

I would like have a f value 50.23. That is to say. I want do it:

Serial.println(f); and obtain 50.23

thanks so much and i apologise for my bad english

atof?

What do the characters c[0] through c[19] look like and why are you starting with element 20?

econjack:
What do the characters c[0] through c[19] look like and why are you starting with element 20?

Other information for example

AWOL:
atof?

I belive isn't useful in my problem becouse its work if you have got a string. But I have got a chain with other things that not interest for my and I should separate the information of interest. I belive...

I belive isn't useful in my problem becouse its work if you have got a string.

So, get a string, and don't reinvent the wheel.

wargadex:
I belive...

Your belief is wrong.

char c[50] = "....-....-....-....-50.23whatever";

void setup() {
  Serial.begin(115200);
  float f = atof(c+20);
  Serial.print(F("Value is "));
  Serial.println(f);
}

void loop() {}
Value is 50.23

Whandall:
Your belief is wrong.

char c[50] = "....-....-....-....-50.23whatever";

void setup() {
  Serial.begin(115200);
  float f = atof(c+20);
  Serial.print(F("Value is "));
  Serial.println(f);
}

void loop() {}





Value is 50.23

But what if c[25] is another digit?

Assuming it's always the same length, I'd copy it to a temp buffer with 'strncpy()' first, then use 'atof()'.

But what if c[25] is another digit?

You've got a stupid encoding system or protocol?

OldSteve:
But what if c[25] is another digit?

char c[50] = "....-....-....-....-50.2312345whatever";

void setup() {
  Serial.begin(115200);
  char xchange = c[25];
  c[25] = 0;
  float f = atof(c+20);
  c[25] = xchange;
  Serial.print(F("Value is "));
  
  Serial.println(f);
}

void loop() {}

Value is 50.23

AWOL:
You've got a stupid encoding system or protocol?

True. It's just that he didn't say, so I was mentioning the an alternative in case he had consecutive values of a similar length without separating characters. (I'd probably use separating characters.)

Whandall, I like your 'xchange' method.

AWOL:
So, get a string, and don't reinvent the wheel.

I need use a char array becouse I recive information from Sim chip and I need analyze this information character to character that is to say, i cant get a string.

Whandall:

char c[50] = "....-....-....-....-50.2312345whatever";

void setup() {
 Serial.begin(115200);
 char xchange = c[25];
 c[25] = 0;
 float f = atof(c+20);
 c[25] = xchange;
 Serial.print(F("Value is "));
 
 Serial.println(f);
}

void loop() {}





Value is 50.23

Thanks, the atof(c+20) is useful for my case becouse after of last number I have blank space and this instruction get exactly the number that I want.
However I think do it:
K[0]=c[25];
K[1]=c[26];
........ and use atof(k), is more best than change de C array values,

Thaks so much

I need use a char array ... i cant get a string.

Doesn't make any sense.

AWOL:
Doesn't make any sense.

I know what a char array and what a C string is, thanks.

Did you read @Whandall's solution in reply #9?