This at this: what happens if a user enters more than 80 characters? This is a serious problem, you have to fix it. With the type
std::string
, you don't have to use the
char[]
type at all and care about it. If you choose to use
std::string
, input it, not null-terminated string. Also, for
std::string
, you don't need to check up null character: use
string::length()
instead. Please review this class thoroughly:
http://www.cplusplus.com/reference/string/string[
^].
Also, you repeat "80" twice. This is not supportable. Define it as a constant explicitly.
You can use and compare
string
values, but this is not efficient. (Yes, I understand that performance is not critical at all, but aren't you do it for learning programming? This is a good reason to try to do the very best.) Here is what you can do: using a constant string, just compare two characters in a loop, starting from leftmost and rightmost character, until you reach the middle. It should work for both odd and even lengths, as well as empty string (and empty string is a palindrome). This way, you can break from the loop at first discrepancy you account, without checking up all the characters.
—SA