reverse
I keep getting no output for my string reverse
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
#include <cstring>
using namespace std;
//Function Prototype
void printReverse(char *s);
int main( )
{
char str[81];
cout << "Enter a string: " ;
cin >> str;
cout << "The reversed string is:\n";
printReverse(str);
return 0;
}
void printReverse(char *s)
{
if (*s != '\0')
{
printReverse(s+1);
cout << *s;
}
}
|
Enter a string: Hello
The reversed string is:
olleH |
Works for me.
(as long as you only enter 1 word)
I kept trying it, but then when i reread it I noticed the hello backwards part was inline with the press any key to continue
thanks for your help
Topic archived. No new replies allowed.