I am reading K&R and trying to do the excercise involving writing a version of strcat (attach one string to the end of the other) using pointers. This is what I have:
#include<stdio.h>
void mystrcat(char *s,char *t)
{
while(*s++);
*s--;
while(*s++ = *t++);
}
int main()
{
int size = 1024;
char *s1, *s2;
s1 = malloc(size);
s2 = malloc(size);
s1 = "Hello ";
s2 = "World";
mystrcat(s1,s2);
printf("%s",s1);
return 0;
}
The program runs but crashes straight away, not very experienced with pointers so can't work out the error.