I'm trying to compare if a string is the same forwards as backwards (for example bob is the same backwards as forwards etc)
I managed to get the string to reverse and store the reverse string in another string variable
However when I try to compare the two I never get the right answer, its always stuck on a false answer.
thats the code I'm using, I've also tried the == deal with no success.Code:line = "bob"; int len = line.length(); for (int i=0; i<len; i++) { if (isalnum(line[i])) { nospc = nospc + line [i]; } } cleaned = nospc; int len2 = nospc.length(); for (int h=0; h<len2; h++) { cleaned[h] = tolower(cleaned[h]); } int len3 = cleaned.length(); for (int x=len3; x>=0; x--) { lincomp = lincomp + cleaned[x]; } isPali = !cleaned.compare (lincomp);
Any suggestions?