help with palindrome program

I posted yesterday my program for the palindrome and it consisted of the last parts because I was only checking whether a sentence is a palindrome or not.However, I have to check if a whole sentence is a palindrome or not,like:Madam I'm adam..ignoring spaces and punctutations.The basic idea is to copy the first char array into another by using 2 nested for loops as shown here. However, I'm not getting correct results.why?
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]))//if the charecter is alphanumeric then copy it to other array
{for(j;j<length1;j++)
sentence[j]=sentence1[i];
}
}
int length=strlen(sentence);

for (int j=0;j<(length/2);j++)
{
if(toupper(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;

}
Last edited on
use "string" and ignore white spaces !
Last edited on
how? i should alsoshould ignore punctuations
i think the compiler is not really knowing what is the length of sentence.I mean it might be taking it as 100 not the real length
please help me.
Topic archived. No new replies allowed.