I wrote this following in-place reverse function and it works fine.
However, when I googled for a solution, I found plethora of more complex solutions but nothing this simple. Will the following not work for certain inputs or has some performance issues?
void reverse(char* str) {
int n = strlen(str);
char temp;
for (int i=0; i<n/2; i++) {
temp = str[i];
str[i] = str[n-i-1];
str[n-i-1] = temp;
}
}
int main() {
char input[] = "Reverse Me!";
reverse(input);
return 0;
}