AWOL:
Yup.
char myArray[] = "Hello World";
void setup() {
Serial.begin(9600);
Serial.print("myArray : ");
Serial.println(myArray);
strcpy(myArray, "");
Serial.print("myArray : ");
Serial.println(&myArray[1]);
}
void loop() {
}
Noted and thanks for the explanation.
As it turns out, I needed to do something similar within a function a few days ago, where I was using a buffer.
My solution was to do this :
char buffer[75];
int bufSize = sizeof(buffer);
Serial.print("Buffer Size : ");
Serial.println(bufSize);
//Flush Buffer
for (int i = 0; i <= bufSize; i++) {
buffer[i] = '\0';
}
Sketch uses 14,480 bytes (5%) of program storage space. Maximum is 253,952 bytes.
Global variables use 1,297 bytes (15%) of dynamic memory, leaving 6,895 bytes for local variables. Maximum is 8,192 bytes.
Today I remembered this thread and thought I would check/test the solutions offered here.
The answer in reply#1 does not work for my sketch - It sends the function into a continuous loop.
char buffer[75];
int bufSize = sizeof(buffer);
Serial.print("Buffer Size : ");
Serial.println(bufSize);
//Flush Buffer
buffer[0] = '\0';
The answer in reply #4 worked.
I used it like this :
char buffer[75];
int bufSize = sizeof(buffer);
Serial.print("Buffer Size : ");
Serial.println(bufSize);
//Flush Buffer
memset(buffer, '\0', bufSize);
Sketch uses 14,474 bytes (5%) of program storage space. Maximum is 253,952 bytes.
Global variables use 1,297 bytes (15%) of dynamic memory, leaving 6,895 bytes for local variables. Maximum is 8,192 bytes.
The memset() version compiles slightly smaller than my version, but which is more efficient?