I have the following code:
It gives me a segfault when I modify any element in the character string. Why is that? The first two statements print fine but as soon as I modify the value of any element in the character string it gives me an error! I have tried hard but I can't find an explanation for the segfault. For the statement that is causing the segfault I tried str[3] = 'a'; but that too is giving me the same error.
#include<stdio.h>
#include<stdlib.h>
void stringmodify(char *);
int main()
{char *array = "BLAH BLAH";
stringmodify(array);
return 0;
}
void stringmodify(char *str)
{
printf("%s\n", str);
printf("%c\n", str[3]);
*(str+3)='a';
}