Write a program to create palindrome words by using the string entered by users. Your program should have 2 strings: the first string is used to store input text from the user and the second string is to store the same input text from the user in reverse direction. Display the palindrome words at the end of your program.
#include <iostream>
//#include <string> //uncomment if using std::string
usingnamespace std;
int main() {
char str1[255], str2[255]; //comment this if using std::string
//string str1, str2; //uncomment if using std::string
cout << "please Enter the text " << ": "<<"\n";
cin >> str1;
//comment all below if using std::string
int endIndex = 0;
for(; str1[endIndex] != '\0' && str1 < 255; endIndex ++); //find the end of the input
for(int i = endIndex, int i2 = 0; i >= 0; i --, i2 ++) {
str2[i2] = str1[i];
}
cout << str1 << str2 << endl;
//uncomment all below if using std::string
/*
for(int i = str1.length() - 1; i >= 0; i --) {
str2 += str1[i];
}
cout << str1 << str2 << endl;
*/
return 0;
}
I should use a string but I am facing a problem with applying it in the program that you gave me
1 2 3 4
int endIndex = 0;
for(; str1[endIndex] != '\0' && str1 < 255; endIndex ++); //find the end of the input
for(int i = endIndex, int i2 = 0; i >= 0; i --, i2 ++) {
str2[i2] = str1[i];