Mohammad Rastkar, thanks for the reply... The code runs in windows platform but the it does not work in a g++ compiler in ubuntu? The strrev is not recognized. Is there any other way?
I have a modifed code that gets the length and swap places to show reversal of text. The only problem is that what would be the statement for analyzing each character and then tells if it is a palindrome or not. Hope you could still help me... Thanks in advance!
Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main () {
char str[20];
char rev[20];
int cc=0;
int i,z=0;
cout << "Please enter a word: ";
cin.getline (str,20);
i = strlen(str);
// places reverse string
for (z=0;z<=i;z++)
{
rev = str[i-z];
}
// displays original string
cout << "Original message " ;
for (z=0;z<=i;z++)
{
cout << str;
}
cout << endl;
// displays reversed string
cout << "Reversed message " ;
for (z=0;z<=i;z++)
{
cout << rev;
}
// I guess there should be if statements here
cout << endl;
return 0;
}
Enter your message below
Sign in or Join us (it's free).