are you doing A level computing by any chance?
I am and are doing the same thing, except in VB
jbennet
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
Hmm... something looks fishy:
char temp[255] = {'\0'};
for (i=0; i<length; i++)
{
if ((temp[i] >= 'a') && (temp[i] <= 'z'))
temp[i] = char(int(temp[i]) - 32);
Why are you checking the value of temp right after you give initalize it with \0 ? Perhaps in the if() statement you wanted to use inputString instead?
Hope this helps
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
How are you defining a palindrome? Obviously, it means that the string is symmetric about its middle, but how do you handle non-alphabetic characters? For instance, if you check that every char is between 'a' and 'z', you'll miss out on capital letters (easily resolved with the tolower(char) function found in <cctype> ), but you also miss numbers and special characters. The last of those is probably good to skip, but numbers you may want to keep (you do have them in your test file, afterall).
If I were to write this, I would implement a loop which kept 2 indices into inputString. One would start from the back, and one from the front. For each one, I would find the first alphanumeric value ( isalnum(char) ) that hasn't been checked. Compare the two and either return false if they don't match or continue checking until the two indices cross each other. If they do cross, return true.
Oh, before I forget: isalpha and isalnum both return non-zero (i.e. true) if the given char is a letter or letter-or-number, respectively.
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
I'm sure he's been waiting around for 4 months just hoping you'll give him a solution. :rolleyes:
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944