Here's a part of my code, where I am trying to reverse a string recursively:
char reverse[10];
gets(reverse);
reverseString(reverse, (strlen(reverse) - 1));
void reverseString(char ar[], int n)
{
if (n == 0)
{
return;
}
else
{
int temp = ar[n];
ar[n] = *(ar);
*(ar) = temp;
reverseString((ar + 1), (n - 1));
}
}
When I enter the string "hello" it changes the string to "ohell". I need it to reverse the string totally to "olleh". Can someone help?
gets, it's not even in the latest standard anymore.