I'm perplexed as to why the following doesn't work:
char * f = "abcdef";
strcpy(f, "abcdef");
printf("%s",f);
char s[] = "ddd";
strcpy(&s[0], "eee");
printf("%s", s);
In both examples strcpy received a char * yet on the first example it dies a horrible death.
"abcdef"
and "ddd"
are string literals which may reside in a read-only section of your address space. char s[] = "ddd"
ensures this literal is copied to stack - so it's modifiable.