This is a program to copy string1 to string2 from K&R book.
#include <stdio.h>
void strcpy_m(char *t1, char *t2);
int main()
{
char *s1 = "this is 1st";
char *s2 = "this is second";
strcpy_m(s1, s2);
printf("%s\t%s\n",s1, s2);
return 0;
}
void strcpy_m(char *t1, char *t2)
{
while((*t2 = *t1) != '\0'){
t2++;
t1++;
}
}
On executing this program I got segmentation fault. What is the reason?