I have this simple C code:
char *foo = "ABCDEFGH";
foo[2] = 'Z';
printf("%s\n", foo);
I expect the output is:
ABZDEFGH
I got this error:
Segmentation fault
I know char *
is pointer and different with char[]
.
In my real project, foo
is variable that come from function that return char *
. That's why I ask.
The question is how do I achieve what I expect in output?