Just for full disclosure, this is a homework assignment.
I need to reverse a char string using a recursive function that accepts only a "char *string" input
I've done a lot of googling and whatnot, but just can't seem to figure it out. If I could use a void function, this would be done hours ago, but alas, that's not allowed.
The following code returns nothing, we're not allowed to change the function signature either
char *reverseString(char *string)
{
if (*string =='\0') return string;
else
{
return reverseString(string + 1) + *string;
}
}
this is my multiple attempts at calling this function from the main to get output from it, and though the code runs, I get no output in the console
char Tstring[] = "TestString";
cout << reverseString(Tstring);
cout << *reverseString(Tstring);
char *answer2 = reverseString(Tstring);
cout << *answer2;
I'm not asking for a direct solution obviously, but I'm having trouble wrapping my head around how to do this using a pointer as an input and whatnot. Any tips or nudges in the right direction are appreciated