Hello all,
I'm fairly new to C++ and Arduino, and I'm finding the char array hill difficult to climb. It's not made any easier when I have code that compiles and runs as expected on an Arduino Mega, but fails to compile on a "Generic ESP8266 Module".
Can anyone offer some insight as to why I either have perfectly valid code that is not compiling (ESP8266), or I have invalid code that IS compiling (Arduino Mega)?
void parse_metar () {
Serial.println(F("[PARSING]"));
// If no metar was returned, print and then get out since there's nothing to parse
if (strstr(metar, "METAR")) {
Serial.println(metar);
return;
}
char *ptr = NULL; // pointer for space-separated chunk of metar data
char *visibility = 0; // whole number holder for visibility that includes a fraction (eg. 2 1/2)
ptr = strtok(metar, " ");
while (ptr != NULL) {
if (strstr(ptr, "RMK")) {
// we can bail here
break;
}
if (strlen(ptr) == 1 && strspn(ptr, "1234567890") == 1) {
// Fractional visibility so hold on to the whole number
visibility = ptr;
} else if (strrchr(ptr, 'SM')-ptr+1 == strlen(ptr)) {
Serial.print("Visibility: ");
if (atoi(visibility) > 0) {
// Need to recombine the whole number portion of the visibility data (eg. 2 1/2)
Serial.print(visibility); Serial.print(" "); Serial.println(ptr);
strcat(visibility, *ptr); // <<<< ERROR REFERS TO THIS LINE
check_visibility(*visibility);
} else {
check_visibility(*ptr);
}
} else if (strstr(ptr, "BKN") || strstr(ptr, "OVC")) {
Serial.print("Cloud Layer: "); Serial.println(ptr);
check_ceiling(*ptr);
}
ptr = strtok(NULL, " ");
}
}
The error I get is:
char *strcat (char *__restrict, const char __restrict);
| ^~~~~~~~~~~~
invalid conversion from 'char' to 'const char' [-fpermissive]
If the error is accurate, how/why does compilation succeed on a different device?
Just taking a stab, I removed the * from the second argument and it compiles, but it crashes the ESP when run.
I am apparently too thick to comprehend this business of char arrays so any help is appreciated.