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 <stdio.h>
#include <string.h>
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;
}