Easy Tutorial
❮ C Environment Setup C Exercise Example5 ❯

C Language Example - String Reversal

C Language Examples

Using recursion to reverse a string.

Example - String Reversal

#include <stdio.h>
void reverseSentence();

int main()
{
    printf("Enter a string: ");
    reverseSentence();

    return 0;
}

void reverseSentence()
{
    char c;
    scanf("%c", &c);

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

Output result:

Enter a string: tutorialpro
oprolauti

C Language Examples

❮ C Environment Setup C Exercise Example5 ❯