Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Testing to see if a word is a palindrome. Using pointers and not arrays?? My cod

ID: 3562407 • Letter: T

Question

Testing to see if a word is a palindrome. Using pointers and not arrays??

My code is:

bool testPalindrome(char *str)
{
   char *front = str;
   char *rear = str-strlen(str)-1;
   str = str + strlen(str) - 1;
  
  
   for (unsigned i = 0; i<strlen(str); i++)

{
       if (*front++ != *rear--)
       {
           cout << "Not a Palindrome." << endl;
           return false;
       }
       else
       {
           cout << "It's a Palindrome." << endl;
           return true;
       }
   }
   return false;
}

It is saying everything is not a palindrome even if it is.

what is wrong?

and thanks for the help.

Explanation / Answer

/*Please find the following Solution

If you find its helpful please rate.

If you have any doubts please comment*/

#include<iostream>
using namespace std;
bool testPalindrome(char *str);
int main()
{
   char str[30]="hao";
   return 0;
}
bool testPalindrome(char *str)
{
char *front = str;
char *rear = str-strlen(str)-1;
str = str + strlen(str) - 1;
  
  
for (unsigned i = 0; i<strlen(str); i++)

{
if (*front++ != *rear--)
{
cout << "Not a Palindrome." << endl;
return false;
}
else
{
cout << "It's a Palindrome." << endl;
return true;
}
}
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote