Float To Char function error

So, I want to change the a float input to a string or a char so I can write in the serial monitor to calculate circle intersection, Code:

    char cInter1_x[20];
    char cInter1_y[20];
    char cInter2_x[20];
    char cInter2_y[20];
    String sInter1_x;
    String sInter1_y;
    String sInter2_x;
    String sInter2_y;

String floatToChar(float inter, char temp[20]) {
dtostrf(inter,9,7,temp);
String answer = String(temp);
return answer;
}

I did this function to every string but when I try to println it this error appears:

invalid operands of types 'const char [46]' and 'const char [3]' to binary 'operator+'

Thank you in advance

Please post a small example program that shows the error rather than a meaningless snippet of code out of context.

Alright this is pretty much it:

 char cInter1_x[20];
    char cInter1_y[20];
    char cInter2_x[20];
    char cInter2_y[20];
    String sInter1_x;
    String sInter1_y;
    String sInter2_x;
    String sInter2_y;
    float a, dx, dy, d, h, rx, ry;
    float point2_x, point2_y;

    // dx and dy are the vertical and horizontal distances between
    // the circle centers.
    
    dx = x1 - x0;
    dy = y1 - y0;

    // Determine the straight-line distance between the centers. 
    d = sqrt((dy*dy) + (dx*dx));

    // Check for solvability. 
    if (d > (r0 + r1))
    {
        // no solution. circles do not intersect. 
        return false;
    }
    if (d < abs(r0 - r1))
    {
        // no solution. one circle is contained in the other 
        return false;
    }

    // 'point 2' is the point where the line through the circle
     //intersection points crosses the line between the circle
     //centers.
   

    // Determine the distance from point 0 to point 2. 
    a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;

    // Determine the coordinates of point 2.
    point2_x = x0 + (dx * a/d);
    point2_y = y0 + (dy * a/d);

    // Determine the distance from point 2 to either of the
    // intersection points.
   
    h = sqrt((r0*r0) - (a*a));

    // Now determine the offsets of the intersection points from
    // point 2.
    
    rx = -dy * (h/d);
    ry = dx * (h/d);

    // Determine the absolute intersection points. 
    float intersectionPoint1_x = point2_x + rx;
    float intersectionPoint2_x = point2_x - rx;
    float intersectionPoint1_y = point2_y + ry;
    float intersectionPoint2_y = point2_y - ry;
    
    sInter1_x = floatToChar(intersectionPoint1_x, cInter1_x);
    sInter1_y = floatToChar(intersectionPoint1_y, cInter1_y);
    sInter2_x = floatToChar(intersectionPoint2_x, cInter2_x);
    sInter2_y = floatToChar(intersectionPoint2_y, cInter2_y);
    println("INTERSECTION Circle1 AND Circle2:  " +  "(" + sInter1_x + "," + sInter1_y + ")" + " AND (" + sInter2_x + "," + sInter2_y + ")");

String floatToChar(float inter, char temp[20]) {
dtostrf(inter,2,2,temp);
String answer = String(temp);
return answer;
}

Why bother to convert a float to a char array when Serial.print() will happily take a float and do all that for you behind the scenes?

Delta_G:
Why bother to convert a float to a char array when Serial.print() will happily take a float and do all that for you behind the scenes?

Because my data will keep be printed second after second and I need everything to be organized.

println("INTERSECTION Circle1 AND Circle2: " + "(" + sInter1_x + "," + sInter1_y + ")" + " AND (" + sInter2_x + "," + sInter2_y + ")");

Look into sprintf(), it should make things easier for you.
http://www.cplusplus.com/reference/cstdio/sprintf/

Bakr:
Because my data will keep be printed second after second and I need everything to be organized.

That's no reason to use Strings. You could do the same with cleverly placed used of Serial.print vs Serial.println or you could use the sprintf method noted above.

Organized data:

Serial.print("A = ");
Serial.print(A);
Serial.print("   B = ");
Serial.print(B);
Serial.print("   C = ");
Serial.println(C);

Get's you (with hypthetical values for the variables):

A = 3   B = 4   C = 10
A = 5   B = 6   C = 12
A = 5   B = 2   C = 11
A = 5   B = 7   C = 14

I don't know how it gets more organized than that.

or you could use the sprintf method noted above.

Not with floats. The %f format is not supported.

Which line in the sketch you posted creates that compilation error ?

michinyon:
Which line in the sketch you posted creates that compilation error ?

This line: println("INTERSECTION Circle1 AND Circle2: " + "(" + sInter1_x + "," + sInter1_y + ")" + " AND (" + sInter2_x + "," + sInter2_y + ")");

Delta_G:
That's no reason to use Strings. You could do the same with cleverly placed used of Serial.print vs Serial.println or you could use the sprintf method noted above.

Organized data:

Serial.print("A = ");

Serial.print(A);
Serial.print("   B = ");
Serial.print(B);
Serial.print("   C = ");
Serial.println(C);





Get's you (with hypthetical values for the variables):



A = 3   B = 4   C = 10
A = 5   B = 6   C = 12
A = 5   B = 2   C = 11
A = 5   B = 7   C = 14





I don't know how it gets more organized than that.

But again we come to the problem of Serial.println()

This is nonsense. You can't just "ADD" stuff like this.

 println("INTERSECTION Circle1 AND Circle2:  " +  "(" + sInter1_x + "," + sInter1_y + ")" + " AND (" + sInter2_x + "," + sInter2_y + ")");

Why don't you just break it down into separate lines something like this

Serial.print("INTERSECTION Circle1 AND Circle2:  (" );
Serial.print( sInter1_x );
Serial.print(",");
Serial.print(sInter1_y);
Serial.print(") AND (");
Serial.print( sInter2_x );
Serial.print(sInter2_y);
Serial.println(")");
 println("INTERSECTION Circle1 AND Circle2:  " +  "(" + sInter1_x + "," + sInter1_y + ")" + " AND (" + sInter2_x + "," + sInter2_y + ")");

I can't see where "println" is defined, but in C/C++, the correct way to concatenate constant strings is NOT to use '+'
Thus char string [] = "The " "quick " "brown " "fox"; is equivalent to char string [] = "The quick brown fox";

I modified my code but the error still pops up.

Bakr:
I modified my code but the error still pops up.

Then you didn't modify it completely.

KenF:
Then you didn't modify it completely.

I didn't see your reply above. It works now. Thank you so much.