The recursive function is only reversing the first and last characters of a string. I've been trying for hours but cant find the error. Any help would be awesome. The code:
#include <iostream>
#include <string>
using namespace std;
void str_reverse(char str[], int length)
{
char temp, temp1;
int starti=0;
int endi = length-starti;
temp1 = str[endi-1];
temp = str[starti];
if(starti>=length-starti)
{
return;
}
str[starti] = temp1;
str[endi-1] = temp;
starti++;
return (str_reverse(str, length-1));
}
int main()
{
string test= "lighter";
str_reverse(test, 7);
cout << "output= " << test;
return 0;
}