I've tried this code snippet to assign '\0' to the last character of a C string
char *words = "words";
words[4] = '\0';
why is line 2 causes segmentation fault?
I've tried this code snippet to assign '\0' to the last character of a C string
char *words = "words";
words[4] = '\0';
why is line 2 causes segmentation fault?
You didn't allocate the space for "words" (you only allocated the pointer to it), so (apparently) it has been placed some where you are not allowed to modify.