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: 
You do not have a recursive function that outputs a string in the reverse order. Also it is a bad idea when a function depends on a global variable.

The function can look the following way as it is shown in the demonstrative program below. Using the function you will be able to output a string in the reverse order in any stream for example in a file.

```
#include <stdio.h>

FILE * string_reverse_output( const char *s, FILE *fp )
{
    if ( *s )
    {
        string_reverse_output( s + 1, fp );
        fputc( *s, fp );
    }

    return fp;
}

int main(void) 
{
    fputc( '\n', string_reverse_output( "Hello World!", stdout ) );

    return 0;
}

```

The program output is

```
!dlroW olleH

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

void reverse();

int main()

{

    printf("Enter String : ");

    reverse();
    return 0;
}

void reverse()

{

    char c;

    scanf("%c", &c);

    if (c != '\n')
    {
        reverse();
        printf("%c", c);
    }
}

```