Since you swap the first and last element of the array, you should recursively
call the function with the remaining n-2
elements (instead of n-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 - 2));
}
}
(I have assumed that reverseString
and reverseAr
in your code are
actually the same functions, perhaps some copy-paste error.)