Part 2) There also exist entire phrases that are palindromes. Capitalization, pu
ID: 3591253 • Letter: P
Question
Part 2) There also exist entire phrases that are palindromes. Capitalization, punctuation, and white space are ignored. Below is a list of palindrome phrases (some which are quite ridiculous and funny Rats live on no evil star Live on time, emit no evil " Do geese see God? .Eva, can Istab bats in a cave? Mr. Owl ate my metal worm " A nut for a jar of tuna .A Santa lived as a devil at NASA Go hang a salami, I'm a lasagna hog Write another function named isPalindrome2() that can detect any of the palindrome phrases above, in addition to the single word palindromes from part 1 There are a number of ways to approach this problem. Since capitalization, punctuation, and white space are ignored, here is a suggestion for one way to write isPalindrome2() Force all the letters in the string to be lowercase. Develop and use a yoid function named toLower() that takes a pass by reference char array as input, and updates the array by changing the value of every capital letter to lowercase. Hint: examine the ASCII table below, notice a simple relationship between capital and lowercase letters? Create a new local array (also 50 elements long), and construct the modified string without any punctuation or space. For example: " Eva, can I stab bats in a cave? Would become: evacanistabbatsinacave Hint: when copying the string, make sure you either copy the null character, or append it to the new string so it'ssl a valid C-style string that has a valid terminator (i.e.'e) Now that you've forced lowercase and removed punctuation and whitespace, simply pass the newly constructed string to your isPalindrome() function, and return it's Boolean output.Explanation / Answer
Here is code.
I this code i have written isPalindrome() separatly to check pilandrome of sentence.
To remove punctuations and spaces , I wrote code in main() function.
-------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<ctype.h> // THis library for to remove punctuations and spaces
#include<string.h>
#define TRUE 1
#define FALSE 0
typedef int Bool;
Bool isPalindrome(char str[]);
main()
{
char string[1000], chr;
int i = 0;
printf("Enter a message: ");//Enter input string and at end please press Enter for working
while((chr = getchar()) != ' '){
if(isspace(chr)==FALSE && ispunct(chr)==FALSE) // Remove spaces and punctuations
{ string[i] = tolower(chr);
i++;
}
}
string[i] = ''; // Append to end of string
printf(" ");
if(isPalindrome(string))
printf("The given sentence is Palindrome ");
else
printf("The given sentence is not a palindrome ");
return 0;
}
Bool isPalindrome(char str[])
{
int left = 0;
int right = strlen(str)-1;
while (left<right)
{
if(str[left] != str[right])
return FALSE;
left++;
right--;
}
return TRUE;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.