I'm currently playing a bit with C and trying to understand strings. Can somebody please explain why this is working:
char test[] = "test";
And why the following does not?
char test[255];
test = "test";
Because this is an initialization:
char test[] = "test";
and this is an assignment:
test = "test";
and you cannot assign arrays in C (and strings in C are just arrays).
Your best bet is to copy the string using strcpy() (or to be safe, strncpy()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With