I have to write a program that checks whether a sentence is a palindrome or not.I had no problem checking a word, but checking a sentence that contains spaces and quoatation marks made results incorrect. Basically to solve the problem and ignore the spaces and marks, I copied the initial array to another array that doesnt contain those and worked with the second array.However, I'm not getting correct results.
void main()
{
cout<<"Enter the sentence you want to check if it is palindrome or not"<<endl;
char sentence1[100];
char sentence[100];
cin.getline(sentence1,100);
int length1=strlen(sentence1);
bool palindrome=true;
int j=0;
for(int i=0;i<length1;i++)
{
if(isalpha(sentence1[i]))
{for(j;j<length1;j++)
sentence[j]=sentence1[i];
}
}
int length=strlen(sentence);
for (int j=0;j<(length/2);j++)
{
if(tolower(sentence[j])!=tolower(sentence[length-j-1]))
{
palindrome=false;
break;
}
else
palindrome=true;
}
if(palindrome==true)
cout<<"This is a palindrome"<<endl;
else
cout<<"This is not a palindrome"<<endl;
}