9I am learning pointers from K&R. I was trying to implement strcat (ubuntu, gcc). The code is compiling but when I run it, i get the segmentation fault error. I searched the web for it, but all i could know is that I am "trying to access a memory location that I am not supposed to or allowed to access". But, I could not find the error in the code.
#include <stdio.h>
void xstrcat(char *s, char *t);
int main(void) {
char *s = "hel";
char *t = "lo.";
xstrcat(s, t);
printf("%s",s);
return 0;
}
void xstrcat(char *s, char *t) {
while(*s)
s++;
while(*s++ = *t++)
;
}
Please tell me where exactly is the error and why?