Solved programming problem

String Reverse with Recursion in C.

Source code

#include <stdio.h>

void rev(char *ptr)

{

    if(*ptr)

    {

        rev(ptr+1); ///calling the function until null

        printf("%c",*ptr); ///print the pointer string by character

    }

}

int main()

{

    char str[100];

    printf("Please Enter a Massage: ");

    gets(str);

    char *ptr=str;

    printf("
Reverse String: ");

    rev(ptr); ///sending the pointer string

    return 0;

}

Output

Please Enter a Massage: code to haven

Reverse String: nevah ot edoc

Join the discussion

Add your comment