I am trying to reverse a string literal with the use of pointers, though my code received SEGSIGV signal on *head=*tail
line
char* reverse(char* input, int n) {
char temp;
char* head= input;
char* tail= &input[n-1];
while(head<tail){
temp=*head;
*head=*tail;
*tail=temp;
head++;
tail--;
}
return input;
}
int main(void){
char* sentence= "All work and no play makes jack a dull boy";
reverse(sentence, strlen(sentence));
printf("%s", sentence);
return 0;
}
I don't know if I am trying to access restricted memory segment.