This is my first post. I am trying to copy characters from one pointer to the end of another however a segmentation fault is caused. What is the appropriate way to write this?
char *my_strcat(char *dest, char *src) {
while (*dest != '\0')
dest++;
while (*src != '\0'){
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return dest;
}
int main(void) {
char *p = "Hello";
char *q = "Carl";
printf("%s\n", my_strcat(p, q));
}
The only error that it causes is a segmentation fault.
Thank you!