Compare Original and Reverse Strings
Finally, we will compare the original and reverse strings to check whether the input string is a palindrome or not.
if(strcmp(inputStr, reverseStr) == 0) {
cout << inputStr << " is a palindrome." << endl;
} else {
cout << inputStr << " is not a palindrome." << endl;
}
Full Code
#include <iostream>
#include <string.h>
using namespace std;
int main() {
char inputStr[100];
cout << "Enter a string: ";
cin >> inputStr;
int strLength = strlen(inputStr);
char reverseStr[strLength];
for(int i = 0; i < strLength; i++) {
reverseStr[i] = inputStr[strLength - 1 - i];
}
if(strcmp(inputStr, reverseStr) == 0) {
cout << inputStr << " is a palindrome." << endl;
} else {
cout << inputStr << " is not a palindrome." << endl;
}
return 0;
}