+ 3
#include <iostream> #include <string>//this is for the function strlen() void swap(char *thisChar, char *withThisChar) {//this will swap and change the actual word char temp = *thisChar; *thisChar = *withThisChar; *withThisChar = temp; } char word[] = "civic"; int nChars = strlen(word);//strlen() is part of: #include <cstring>. It returns the length of a string char *pWordStart = word; char *pWordEnd = word + nChars - 1; int main() { string saveWord = word; while (pWordStart < pWordEnd) { swap(pWordStart, pWordEnd); pWordStart++; pWordEnd--; } string reversedWord = word; if (saveWord == reversedWord) { cout << saveWord << " is a palindrome!" << endl; } else cout << "'" << saveWord << "' is not a plindrome :(" << endl; return 0; }
21st Oct 2016, 7:24 PM
Zeke Williams
Zeke Williams - avatar