I'm trying to take a string: "Two words" and turn it into "sdrow owT".Code:int main(void){ int size, start; char *string = "Two words"; size = (int) strlen(string); start = 0; reverseString(string, start, size - 1); return 0; } void reverseString(char *string, int start, int end){ char temp; while(end > start){ temp = string[start]; string[start] = string[end]; /* <------ crashes here */ string[end] = temp; start++; end--; } printf("reversed string: %s\n", string); }
I guess there is something wrong with my function though.
The program just hangs for a while after I execute it and then it crashes.
Any suggestions? Thanks!