/*
Forum: https://forum.arduino.cc/t/issue-with-reading-writing-characters-in-string-array/1198946/2
Wokwi: https://wokwi.com/projects/383743348014536705
*/
char nmea[] = "abcdefg";
int lengthOfNmea = sizeof(nmea)/sizeof(nmea[0]);
void setup() {
Serial.begin(4800);
nmea[3] = 'L'; // set nmea[3] to "L"
Serial.println(nmea);
// Use the function strlen to get the text length
Serial.print("strlen :\t");
Serial.println(strlen(nmea));
// Use the calculation sizeof(nmea)/sizeof(nmea[0]) to get the size in memory
// allocated by char nmea[] = "abcdefg";
// It is one char/byte more than the letters above ...
// because the end of the char string is marked by a zero = '\0'
// that requires an additional entry
Serial.print("sizeof-calc :\t");
Serial.println(lengthOfNmea);
Serial.print("[ ");
for (int i=0; i<lengthOfNmea;i++){
Serial.print(nmea[i],HEX);
Serial.print(" ");
}
Serial.println(" ]");
Serial.print("[ ");
for (int i=0; i<lengthOfNmea;i++){
Serial.print(nmea[i]);
Serial.print(" ");
}
Serial.println("]");
}
void loop() {
}