I am a beginner programmer. I wrote the following code to copy the one string into other, using pointers. But I am not getting the output. The compiler says segmentation fault. I have gone over and over the program, but to no avail. I am not able to locate the fault, and how to fix it. It would be hard to believe but I have been stuck for almost 2 hours now. Any help is greatly appreciated.
#include<stdio.h>
char *copy(char*, char*);
int main() {
char *str1 = "avanti";
char *str2 = "ujj";
printf("%s\n", str1);
char *result = copy(str1, str2);
printf("%s", result);
}
char *copy(char *str1, char *str2){
int i=0;
while (*(str2+i) != '\0') {
*(str1+i) = *(str2+i);
i++;
}
*(str1+i) = '\0';
return str1;
}