Problem about convert array of string to char using toCharArray

My code only convert the fraction part of string to char. For example, the string is 123.8724; i get 0.8724
My code is:

if (inbyte == '!'){ // Handle delimiter, ! IS MY endline character.
for (int i =0;i< counter;i++)
{
data*.toCharArray(carray, 12); //put readStringinto an array*

  • float f = atof(carray + 1); //convert the array into an Integer*

  • desiredT = f;*

  • Serial.println(desiredT,5);*

  • }*

  • inbyte = 0;*

  • }*
    }

If you are using the String library you can use standard array logic to access the pointer rather than toCharArray which copies the entire array.

void setup() {
  String data = "123.456";
  char * carray = &data[ 0 ];
  float f = atof( carray  );
  Serial.begin( 9600 );
  Serial.print( f, 5 );
}

void loop() {}

The alternative using toCharArray works like this: ( carray must be an array, or pointer to valid data )

void setup() {
  String data = "123.456";
  
  char carray[ 10 ];
  
  data.toCharArray( carray, 10 );
  
  float f = atof( carray  );
  Serial.begin( 9600 );
  Serial.print( f, 5 );
}

void loop() {}

chenni1:
My code only convert the fraction part of string to char. For example, the string is 123.8724; i get 0.8724
My code is:

if (inbyte == '!'){ // Handle delimiter, ! IS MY endline character.
for (int i =0;i< counter;i++)
{
data*.toCharArray(carray, 12); //put readStringinto an array*

  • float f = atof(carray + 1); //convert the array into an Integer*

  • desiredT = f;*

  • Serial.println(desiredT,5);*

  • }*

  • inbyte = 0;*

  • }*
    }
    [/quote]
    ```

  • if (inbyte == '!')
    {
      /// you get your string into a null terminated array somehow....

char dot = strstr(carray, ".");
    Serial.println(dot);
}

```