I'm trying to use the tolower function from the cctype header ... in this function (to check if a word is a palindrome
int palindrome(const string& w)
{
typedef string::size_type sz;
string ret = w;
sz r = 0;
sz l = w.size() - 1 ;
int check = 0;
while(r != l && r < l)
{
// needs to fix the upper / lower issue
if(isupper(ret[r]))
tolower(ret[r]);
if(isupper(ret[l]))
tolower(ret[l]);
if(ret[r] == ret[l]){
++r;
--l;
}
if(ret[r] != ret[l]){
r = l;
check +=1;
}
}
return check;
}
... so ... if the letter is uppercase ... it'll make it lowercase just to compare them ... but it just ... doesn't work ... the programs just finds AnA to be a palindrome, but Ana not ... can someone help me please?