so this function is meant to get the users word and reverse it, that way it would compare itself to see if is a palindrome or not. Im having trouble comparing both strings, and also when i display the word, i sometimes would miss the middle letter to a weird symbol.
void ReverseWord(char Word[21], char Reverse[], int len)
{
char Temp;
len = strlen(Word); //this gets the length of the word
for (int i = 0; i < len; i++)
{
Temp = Word[i];
Reverse[i] = Word[len + i - 1];
Reverse[len - i - 1] = Temp;
}
cout << Reverse;
if(Word[len] == Reverse[len - 1])
{
cout << "The word you have entered is a palindrome ";
}
else
{
cout << "Thats not a Palindrome";
}
}
for (int i = 0; i < len; i++)
{
Temp = Word[i];
Reverse[i] = Word[len + i - 1];
Reverse[len - i - 1] = Temp;
}
Should be:
1 2
for (int i = 0; i < len; i++)
Reverse[i] = Word[len-i-1] ;
In your comparison, you compare the terminating null value in Word to the last letter in Reverse. That is neither correct nor sufficient to determine if Word is a palindrome.
I suggest working out how you would do this on paper before attempting to code it.