With numbers I can do this, and it prints 5 followed by 10:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int x = 5;
Serial.println(x);
x = 10;
Serial.println(x);
}
void loop() {}
I hoped the same would be true with a string, so I tried this:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
char stringx[]="foo";
Serial.println(stringx);
stringx[]="bar";
Serial.println(stringx);
}
void loop() {}
It fails to compile, highlighting this line:
stringx[]="bar";
with the message:
expected primary-expression before ']' token
Evidently it's not as simple as replacing an int with a new value.
I can do this of course, but I'm really hoping there's a simpler way (not including using a for to do what I did here character by character):
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
char stringx[]="foo";
Serial.println(stringx);
stringx[0]='b';
stringx[1]='a';
stringx[2]='r';
Serial.println(stringx);
}
void loop() {}
To recap: is there a way to replace a string in a way analogous to the way I can overwrite a number?