I am having a bit of trouble with a program I am writing to check if a file that first has the length, then the content contains a palindrome.
For example, if a file contains: 4 aa bb bb aa, disregarding the 4 as the length, my code should be able to recognize aa bb bb aa as a palindrome.
However if a file contains: 4aa bb bb aa, the code does recognize a palindrome... so the space between the 4 and first a is throwing the program off. Any ideas on how can I fix this?
Somewhat confused. If the string has a '4' in the front, then it's not a palindrome unless it also has a '4' in the back. Isn't this actually the desired behaviour?
C-style strings (char*) read in white space. So your string
4 aa bb bb aa
is being evaluated as
aa b aa
which is not a palindrome. (Note the space before the first aa.)
However, with the other string you are not including white space, so your string is being evaluated as
Using streams would probably work, but that would create some other difficulties. I would suggest just getting rid of all of the white space in your programs, or counting the white space as part of it.