Write a function that accepts an array of pointers each poin

Write a function that accepts an array of pointers each pointing to a different name. It then checks each name if it indeed is a palindrome. A palindrome is a name that spells the same is read backwards. For instance \'bilal\' is not a palindrome as it spells \'lalib.\' On the other hand \'hannah\' is a palindrome because she spells \'hannah\' backwards as well. Once verified that the name is a palindrome, the function prints all the names that are palindromes. Show whole program in C++

Solution

Answer:

The function to verify name is a palindrome is given as below :

int palindrome(char* name)
{
size_t value = strlen(name);
if (value == 0) return 0;
if (value == 1) return 1;

char *first_pointer = name;
char *second_pointer = name + value - 1;
while(second_pointer >= first_pointer) {
if (!isalpha(*second_pointer)) {
second_pointer--;
continue;
}
if (!isalpha(*first_pointer)) {
first_pointer++;
continue;
}
if( tolower(*first_pointer) != tolower(*second_pointer)) {
return 0;
}
first_pointer++;
second_pointer--;
}
return 1;
}

 Write a function that accepts an array of pointers each pointing to a different name. It then checks each name if it indeed is a palindrome. A palindrome is a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site