Frankthetech
Well-known member
Hi, so I'm just trying to get a handle on the array (char type) operation.
running this code
2 questions,
why does the address of the lstBuf[40] end up before the oneBuf[10]? oneBuf and twoBuf seem to be in order.
OK so maybe the compiler decides the order, I think.
and why with strcat(oneBuf, twoBuf); does twoBuf[20] end up with 34, and missing the -second- word?
how does twoBuf lose part of itself with a strcat copy?
running this code
Code:
char oneBuf[10]={"is one"};
char twoBuf[20]={"second34"};
char lstBuf[40]={"big array"};
void showdata(){
Serial.print("address of oneBuf --> "); Serial.print(int(&oneBuf),HEX);
Serial.print(" oneBuf = "); Serial.println(oneBuf);
Serial.println();
Serial.print("address of twoBuf --> "); Serial.print(int(&twoBuf),HEX);
Serial.print(" twoBuf = "); Serial.println(twoBuf);
Serial.println();
Serial.print("address of lstBuf --> "); Serial.print(int(&lstBuf),HEX);
Serial.print(" lstBuf = "); Serial.println(lstBuf);
}
void setup() {
Serial.begin(115200);
while(!Serial && (millis()<1000));
Serial.println();
showdata();
strcat(oneBuf, twoBuf); //put more chars into oneBuf then it can hold
Serial.println();
Serial.println("after buffer overflow");
showdata();
}
void loop() {
delay(10);
}
2 questions,
why does the address of the lstBuf[40] end up before the oneBuf[10]? oneBuf and twoBuf seem to be in order.
OK so maybe the compiler decides the order, I think.
and why with strcat(oneBuf, twoBuf); does twoBuf[20] end up with 34, and missing the -second- word?
how does twoBuf lose part of itself with a strcat copy?
Last edited: