char* is a const string, the char in it should be changed liked "s[0]='i'; " changing the string to a char array will be ok.
char s[] = "dog";
printf ("char is %c\n", s[0]);
s[0]='i';
printf ("s = %s\n", s);
Question
Why would this get a segmentation fautl?
char *c = "dog";
printf ("char is %c\n", s[0]);
s[0]='i';
printf ("s = %s\n", s);
output: char is d segmentation fault
Why does it error on the second string? Im just trying to understand it...
Solution
char* is a const string, the char in it should be changed liked "s[0]='i'; " changing the string to a char array will be ok.
char s[] = "dog";
printf ("char is %c\n", s[0]);
s[0]='i';
printf ("s = %s\n", s);