Help with a palindrome checker

I am stuck making a palindrome checker program.

I have viewed an example here: http://www.cplusplus.com/forum/beginner/62531/
and here: http://answers.yahoo.com/question/index?qid=20070123134934AAi3Pwf
but I still am stuck.
Here's my code I made so far:

/*
Write a method to check if the given char array, wordArray, is a palindrome (returns bool).
ie racecar, kayak are palindromes.
*/
#include <iostream>

using namespace std;


2.
Here's my latest version:
/*
Write a method to check if the given char array, wordArray, is a palindrome (returns bool).
ie racecar, kayak are palindromes.
*/

/*
Plan:
1. Take a string and return its reverse.
2. Count the characters in the string
3. If characters are odd, set first half of string, not including middle character.
4. If characters are even, set the first half of the string.
5. Reverse the string so if s1 and s2 are the same, return true, else false.

Note: char array is an array of characters, a string.
*/
#include <iostream>

using namespace std;

int main()
{
cout << "Please enter a word, or words: "
cin >> wordArray;
// Array Palindrome Check[](char, String);
for(i = 0; i < n-1; i--)
if(i == n - 1)
cout << "The given char array, " << wordArray << " is a palindrome.";
else
cout << "The given char array, " << wordArray << "is not a palindrome.";
return 0;
}
//1. Take a string and return its reverse.



bool PalindromeCheck()
{
char[] str = mystring.ToCharArray();
Array.Reverse(str);
string revstring = new string(str);

if(mystring.equals(revstring))
{
True
}else{
false}
}
}
//Reference: http://stackoverflow.com/questions/52002/how-to-check-if-the-given-string-is-palindrome


int main()
{
PalindromeCheck();
// Array Palindrome Check[](char, String);
for(i = 0; i < n-1; i--)
if(i == n - 1)
cout << "The word is a string.";
else
cout << "The word is not a String.";
return 0;
}

bool PalindromeCheck(){

}



3. I don't think this version will work?

/*
Write a method to check if the given char array, wordArray, is a palindrome (returns bool).
ie racecar, kayak are palindromes.
*/
#include <iostream>
#include <cstring>

using namespace std;

bool PalindromeCheck(char* array);

int main()
{
char word[8] = "racecar";
if (PalindromeCheck(word) == true)
cout << "The word is a palindrome.\n";
else
cout << "The word is NOT a palindrome.\n";

return 0;
}

bool PalindromeCheck(char* array)
{
int e = strlen(array)-1;
int s = 0;
while (s < e){
if (array[s] != array[e]){
return false;
}
e--;
s++;
}
return true;
}
Last edited on
Topic archived. No new replies allowed.