#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
usingnamespace std;
bool isPalindrome(constchar*);
int main()
{
string input;
fstream nameFile;
nameFile.open("Xample.txt", ios::in);
if (nameFile)
{
cout << "Now reading from file: " << endl;
// Read an item from the file.
getline(nameFile, input);
// While the last read operation
// was successful, continue.
while (nameFile)
{
cout << input << endl;
//Palindrome function call
if(isPalindrome(input.c_str())){
cout << "It is a Palindrome :) " << endl;
}
else
cout << "It is not a Palindrome :'( " << endl;
// Read the next string.
getline(nameFile, input);
}
//Close when completed
cout << "Done!" << endl;
nameFile.close();
}
else
{
cout << "ERROR: Cannot open file.\n";
}
return 0;
}
//Function to test if string is a palindrome
bool isPalindrome(constchar *input){
int first = 0;
int len = strlen(input); //here is my problem
int last = len - 1;
//begin loop to compare first position with last
while(last > first){
//Loop to
while(!isalnum(input[first]) && !isalnum(input[last])){
first++;
last--;
}
if(tolower(input[first]) != tolower(input[last])){
returnfalse;
}
last--;
first++;
}
returntrue;
}