Hello, I want to declare a large char (byte) array on the heap then print this to serial
I tried this
void setup() {
Serial.begin(9600);
}
void loop() {
char *buffer;
int i = 0;
buffer = (char*) malloc(20);
if (buffer == NULL) Serial.println("sh!t hit the fan");
for( i = 0; i < 19; i++) {
buffer[i] = i;
}
buffer[i] = 0;
Serial.println("before");
Serial.print(*buffer);
Serial.println("after");
delay(1000);
free(buffer);
}
But all that comes out is
"before
after"
(space between the newline and after). What have I done wrong?
Thanks