I am writng a program that takes a string and it must output if it is a palindrome,
A palindrome is a string that is spelled and read the same way forward and backward, it workes fine with one word but if there is spaces or capital lettersor commas it won't work I used getline but without any effect.here is the code.
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <string>
- using namespace std;
- int main ()
- {
- char s[100];
- int i,j;
- bool match=true;
- cin.getline(s,100,'\n');
- cout<<endl;
- i=0;
- j=strlen(s)-1;//because of the \0
- while(match&&(i<j))
- {
- if(s[i]!=s[j])
- match=false;
- i++;
- j--;
- }
- if (match)
- cout<<"It is a palindrome"<<endl;
- else
- cout<<"It is not a palindrome"<<endl;
- return 0;
- }