So I have this code that's supposed to reverse a string and upon printing of the returned result I get a segmentation error.
Now I put in several printf statements to test and I've found that the error is caused by the strcpy function.
I'm confused as to why this is happening, could someone tell me how I can fix it?
Code:char *reverse(char *input) { int i; int j = 0; char *temp = calloc(100, sizeof(char)); for(i=strlen(input)-1; i>=0;i--) { temp[j] = input[i]; j++; } temp[j] = '\0'; strcpy(input, temp); free(temp); return input; }