Create a function called is_palindrome that will return 1 if a given MYSTRING ob
ID: 3553005 • Letter: C
Question
Create a function called is_palindrome that will return 1 if a given MYSTRING object is a palindrome and 0 otherwise. Your function will then examine your string one character at a time, pushing all of the characters that satisfy the isalpha() function in the library ctype to a new, temporary, string and making them all a consistent case with toupper() or tolower(). This will remove all the punctuation and whitespace from the string and make the string easier to test. Now, iterate through the string from the front and back until you cross in the middle and if every character is a match then the string is a palindrome and you should return 1. Your main program does not need to prompt or print anything except for the word yes if the string is a palindrome and no otherwise.The functions that need to be used are here: http://pastebin.com/4jaQcj4c
Create a function called is_palindrome that will return 1 if a given MYSTRING object is a palindrome and 0 otherwise. Your function will then examine your string one character at a time, pushing all of the characters that satisfy the isalpha() function in the library ctype to a new, temporary, string and making them all a consistent case with toupper() or tolower(). This will remove all the punctuation and whitespace from the string and make the string easier to test. Now, iterate through the string from the front and back until you cross in the middle and if every character is a match then the string is a palindrome and you should return 1. Your main program does not need to prompt or print anything except for the word yes if the string is a palindrome and no otherwise.
The functions that need to be used are here: http://pastebin.com/4jaQcj4c
Explanation / Answer
int is_palindrome(char * s)
{
char * s1;
int i,n=strlen(s),cnt=0;
s1=(char *)malloc(sizeof(char)*(n+10));
for( i=0; i<n; i++)
if(isalpha(s[i])) s1[cnt++] = tolower(s[i]);
for(i=0; i<=(cnt/2); i++)
if(s1[i] != s1[cnt-i-1]) return 0;
return 1;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.