Question: I need any given string to be printed in reverse using recursion. I have tried changing the function prototype and definition by changing the return value type and parameter list of the function stringReverse. stdout of this does not print anything for the reverse string and I cannot figure out why.

```
#include <stdio.h>
#define SIZE 100
char stringReverse(void);
size_t i;
unsigned int pass;
int hold;
char a1[SIZE]; 
char a2[SIZE]; 
int main(void) {
    for (i = 0; i < SIZE; ++i) {
        a1[i] = 0;
    }

    printf("Enter a string: ");
    scanf_s("%[^\n]99s", a1);

    printf("%s%s\n\n", "string is:\n", a1);

stringReverse();
}

char stringReverse(void)
{
    for (pass = 1; pass < SIZE; ++pass) {
        if (a1[i] < a1[i + 1]) {
            hold = a1[i];
            a1[i] = a1[i + 1];
            a1[i + 1] = hold;
        }
    }
    printf("%s%s", "reverse is:\n", a2);
}

```

Answer: 
below are recursive functions to reverse a string the first is only prints and the second build the string inside `revstr` buffer and return it to caller.

```
void reverse(char *str) 
{ 
   if (*str) 
   { 
       reverse(str+1); 
       printf("%c", *str); 
   } 
} 

void recrev(char* str, char* revstr, int i)
{
   if (*str) 
   {
       recrev(str+1, revstr, i-1);
       sprintf(revstr + i, "%c", *str);    
   }

}

int main()
{

    char arr[]="hello";
    char revstr[6];
    recrev(arr, revstr, 4);
    printf("%s",revstr);
    return 0;
}

```
Recursion is a massive overkill for this job. But still, if need be, @VladfromMoscow has given an excellent answer using recursion. Might I take the liberty to instead suggest a better solution altogether?

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    printf("Enter your string: ");
    char str[100];
    scanf("%[^\n]s",str);
    str = strrev(str);
    printf("%s",str);
    return 0;
}

```

For more information on how `strrev` works, I suggest you take a look at [`strrev()` function in C](https://www.geeksforgeeks.org/strrev-function-in-c/)