Mcu32
Well-known member
Code:
const char* city = "Yes, the longest name of a city is Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu";
void incident_2()
{
String c;
c.copy(city, 11);
Serial.println("Length of c is:");
Serial.println(strlen(c.c_str()));
Serial.println("Ooops.");
//hint: append() ist broken, too.
//hint: strcpy is always suspicious, and should be checked twice (at minimum....) most of the time, there are better alternatives
//And no, the solution is _not_ to make copy "protected". Do it right.
}
Just use the trivial surrounding code from the prev. thread.