I return a char[300]
array from a function. If I intialize a char*
variable with it, the return is garbled, but not if I append it to a String
. What gives?
const char* post2 = uploadHourCsv(timeNow,pulseChangeHour) ;
String postS2 = "";
postS2 = uploadHourCsv(timeNow,pulseChangeHour) ;
//const char* post2 = { uploadHourCsv(timeNow,pulseChangeHour) };
if( debug ) {
Serial.print("received in loop() as : [");
Serial.println(post2);
Serial.print("String : [");
Serial.println(postS2);
}
...
char postStr[300] = "";
// populate array
if( debug ) {
Serial.print("postStrCsv generated: ");
Serial.println(postStr);
}
return postStr;
postStrCsv generated: 00000003;3| 0.00;8|17.55;9|17.55;10|18.12;11|16.92;20|93817;22|93789;101|6;time|1559646000;
received in loop() as : [000?⸮@⸮⸮?" ⸮⸮?17.55;9|17.58! @0⸮⸮⸮⸮G% @5~`⸮h⸮?⸮⸮
String : [00000003;3| 0.00;8|17.55;9|17.55;10|18.12;11|16.92;20|93817;22|93789;101|6;time|1559646000;
uploadHourCsv
return? Since post2 is declared as a pointer, without any size, the function has to return a pointer to an already allocated string to do this.char postStr[300]
with contents displayed in blockquote.