So i have a program it works which takes in a word reverses it prints it out. BUT! the problem is that the program is without recursion. I need help to convert the function into recursion. Please give me some idea or let me know the syntax if you were able to figure it out.
#include <iostream>
void print_reverse( constchar* cstr )
{
if( cstr != nullptr && *cstr != 0 ) // if the first character is not a null character
{
constchar head = *cstr ; // first character
constchar* tail = cstr+1 ; // rest of the string
print_reverse(tail) ; // first print the rest of the string in reverse
std::cout << head ; // and then at the end, print the first character
}
}