I am trying to write a simple reverse string program and getting the above error. I am unable to understand what I'm doing wrong.
void reverse(char *str) {
char *end, *begin;
end = str;
begin = str;
while (*end != '\0') {
end++;
}
end--;
char temp;
while (begin < end) {
temp = *begin;
*begin++ = *end; //This is the line producing the error
*end-- = temp;
}
}
void main() {
char *str = "welcome";
reverse(str);
}
Need your help. Thanks.