How to cenvert a stream of charachters into float

hello everyone,
I am developing a program using Arduino Mega 1280 and I have the next problem.

I do not how to convert a stream of characters received by Serial port, into float. the thing is that I have a server program sending streams of numbers to the Serial port of the Arduino, this receives all data properly but I need that Arduino converts those numbers into floats, for instance if the server sends the stream of characters 25.25 or -150.963 etc, once they arrived at Serial port and Arduino reads them, how can Arduino converts those into float?

I have tried: cast conversion but it does not work. float (CX), being CX an array of char.

if anyone has an idea i would be glad to get it, thanks

Here is the code that I use to get the stream of characters .
unsigned char data =0;
unsigned char
int i=0,j=0,x=0;
char CX;
float *valor;
void reading_data_from_server();

void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
}

void loop()
{

reading_data_from_server();
}

void reading_data_from_server()
{

if(data=Serial.available()>0)
{
for(i=0;i<=data;i++)
{
CX*=Serial.read();*

  • } *
  • }*

}

char CX[];

Oops.

USE CODE TAGS

float *valor;

What is this for? You most certainly do not want a pointer to float. You want a float.

Of course, casting doesn't work. The atof() function will, if the array of chars is NULL terminated (and sized properly).

Also, your assumption that all of the packet, and nothing but the packet, arrives at once is flowed.

String currentweb = "";
char c = client.read(); // read 1 byte (character) from client
  currentweb += c;
                  
            if (c == '\n' && currentLineIsBlank)
            webCredit = 0;
          commaPosition = currentweb.indexOf(',');
          webCredit =StrToFloat(currentweb.substring(0,commaPosition));
  [\code]

something like this?

something like this?

String currentweb = "";

Nope. Nothing like that.

Something you can try.

// zoomkat 7-30-11 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

/*Very simple serial test code. Copy and paste into the IDE code 
area. Upload via clicking the IDE upload arrow. When upload 
finished, open the serial monitor by clicking the serial monitor 
icon in the upper right of the IDE. Ensure 9600 baud rate is 
selected in the serial monitor. Type something in the serial 
monitor text box and send. What was typed in the text box should 
be sent back to the serial monitor display. */

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);
    char carray[readString.length() + 1]; //determine size of the array
    readString.toCharArray(carray, sizeof(carray)); //put readStringinto an array
    float f = atof(carray); //convert the array into a float
    Serial.println(f);
    readString="";
  } 
}

@Paul, if he reads in the characters as I showed into as char instead of an array, it will work. SInce he is concerned with converting them to a float, this will give him the option to do that.