how to add string to char array

I have two float value like below,

// Read Humidity
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();

then I need to add above sensor’s value to char array… Also I have tried like below… but it show "initializer fails to determine size of ‘INSERT_SQL’"error…

char INSERT_SQL[] = "INSERT INTO test_arduino.sensor (`temperature`,`humidity`) VALUES ('"+String(t,2)+"','"+String(t,2)+"')";

How can I add this float value to char array?

You need to create a temporary buffer and use dtostrf() to convert the float to a string and then build your string up with strcat.

char INSERT_SQL[64] = "INSERT INTO test_arduino.sensor";

char float_buf[16];

dtostrf(temp, 16, 2, float_buf);

strcat(INSERT_SQL, float_buf); strcat(INSERT_SQL, ", and ");

dtostrf(hum, 16, 2, float_buf); strcat(INSERT_SQL, float_buf);

KeithRB: You need to create a temporary buffer and use dtostrf() to convert the float to a string and then build your string up with strcat.

char INSERT_SQL[64] = "INSERT INTO test_arduino.sensor";

char float_buf[16];

dtostrf(temp, 16, 2, float_buf);

strcat(INSERT_SQL, float_buf); strcat(INSERT_SQL, ", and ");

dtostrf(hum, 16, 2, float_buf); strcat(INSERT_SQL, float_buf);

that code is working fine..you save my time and you did a great help for my project. thank you very much. i really appreciated your help.