I would just like clarification on something that has always been a bain to me, strings and pointers (oh yes, that little gem of C programming). Consider this code:
void F(char* p)
char* p2 = NULL;
//p = "ANOTHER TEST";
p2 = strstr(p, "TEST");
strncpy(p2, "FAKE", 4);
int main ()
char str = "TEST STRING";
Right. Obviously F() exists to alter the string passed to it. Here is my confusion.
1) I can alter the string *permanently* via this code, i.e. the output is not TEST STRING but FAKE STRING since it has been altered in F(). If I can operate on 'p' from within F() like this using strstr and strncpy, why does the line commented out not work ? Why can I just not change the string directly via assignment ?
2) The line I have commented out, when removed, causes the program to crash with an access violation (in assembly code). strncpy is what causes the crash, and I cannot see what is going on. Can you ?
Thanks in advance.