Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to get an input from the user as string and compare it with its reversed valued string,if it is equal then it's a palindrome, otherwise not.But I don't know how to store the value of that reverse function in a string so that I can compare it with original one and check it for palindrome.

What I have tried:

I have tried to reverse the string but don't know how to compare it's value with the original string.
Posted
Updated 30-May-23 20:33pm
Comments
Patrice T 31-May-23 1:28am    
Show ypur work so far.

 
Share this answer
 
This is one way you can compare strings : cplusplus.com/reference : strcmp/[^] and this is one way to acquire a string from a user or file : cplusplus.com/reference : fgets/[^]. That also shows you how to store the input in a character array.

YOU need to write the code.
 
Share this answer
 
It would be not an efficient solution to the problem, but, using the algorithm library, you might actually reverse the string:
C++
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  string s = "foobar";
  string r{s};
  reverse(r.begin(), r.end());
  cout << "s='" << s << "', r='" << r << "'\n";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900