Maybe someone can help explain what's going on here.
#include <EEPROM.h>
void setup() {
Serial.begin(115200);
char fn[15];
*fn = filename();
Serial.println(fn);
Serial.println();
for (byte i = 0; i < 15; i++) {
Serial.print(fn[i]);
EEPROM.write(16+i, fn[i]);
}
delay(100);
Serial.println();
char newfn[15];
for (byte i = 0; i < 15; i++) {
newfn[i] = EEPROM.read(16+i);
// Serial.print(EEPROM.read(16+i));
}
Serial.println();
}
void loop() {
}
char* filename() {
char fn[15];
strcpy(fn, "This is a file");
return *fn;
}
Output of this sketch, perfectly as expected:
This is a file
This is a file
done
But when I uncomment line 22 I see the garbage as per this screen shot (sorry, couldn't copy/paste this):
The Serial.println(fn) and Serial.print(fn[i]) get completely messed up somehow. The string of numbers is also not an ASCII encoding of the original string - it looks like the same messed up version of the string that got printed before.
Arduino Pro Mini 5V/16 MHz, Arduino 1.8.5/Linux Mint.