Reverse a string recursively I just finished this exercise where i should reverse a string with a recursive function. First of all, i created a separate function called swap to swap the chars, should i write it as function pointer?. After i call the function recursively untill i reach the base case, the if check if the variable "lenght" is 1 or 0, bacause the string can be even or odd. Any tips to improve this code? i don't know it's seems pretty ugly.

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

void swap(char arr[], int pos, int pos_2){
  char sent = arr[pos_2];
  arr[pos_2] = arr[pos];
  arr[pos] = sent;

}

void recursive_mirror(char arr[], int lenght){


  if(lenght == 0 || lenght == 1){
    return;
  }

  swap(arr, 0, lenght - 1);
  lenght--;
  recursive_mirror(arr + 1, lenght - 1);

}



int main(void) {

  char arr[] = "mirror";
  recursive_mirror(arr,strlen(arr));
  printf("%s\n", arr);
  return 0;
}
swap would be is a nice general purpose swap routine. Notice that in your code you always call it with pos equal to 0. You should either drop this redundant parameter, or make swap even more general purpose by not assuming the semantics of the parameters, e.g.:

void swap(char * ptr1, char * prt2) {
    char ch = *ptr1;
    *ptr1 = * ptr2;
    *ptr2 = ch;
}


In this version, ptr1 and ptr2 do not have to belong to the same array.
recursive_mirror decrements length twice, and the first decrement has a side effect. The (non-existent) purpose of this side effect takes an effort to understand. A direct

  swap(arr, 0, length - 1);
  recursive_mirror(arr + 1, length - 2);


seems more readable).
The base case test can be if (length &lt; 2).

Nitpick: your base case tests fails miserably on a negative length. However, from the very beginning we know that length shall not be negative, so declaring it as an unsigned seems more prudent. At least the intention is documented.