Possible Duplicate:
Why do I get a segmentation fault when writing to a string?
I want to replace a word in a string. Here is the code
char text[] = "This is a list of lists";
char *find = "list";
char* pos = NULL;
pos = strstr(text,find);
strncpy(pos,"test",4)
This works fine but
char *text = "This is a list of lists";
char *find = "list";
char* pos = NULL;
pos = strstr(text,find);
strncpy(pos,"test",4)
This gives a segmentation fault.
In the first example "text" is an array and the data is just copied at that location. In the 2nd one "text" is a pointer. What is issue?