Question: How can I modify my code (see below) to meat the a and b requirements?: a) Modify the function that removes ignores non-letters (i.e., the

How can I modify my code (see below) to meat the a and b requirements?:

a) Modify the function that removes ignores non-letters (i.e., the one that removes spaces and special characters from a string). You have probably defined this as a void-function since it does not need to return any value. Your task is to change the function so that it now returns how many characters that were removed by the function (or 0 if no character were removed). (2p) b) Modify main() so that it displays information of how many characters were removed in order to verify if it was a palindrome. See the example run how this could be displayed (2p)

Example run (user input inbold,comments not partof the output initalic): Enter a sentence: A lemon one space will be removed This sentence is not a palindrome. 1 character(s) were removed. Do you want to enter another sentence (0 for no, 1 for yes)? 1 Enter a sentence: No lemon, no melon. three spaces and two special characters removed This sentence is a palindrome. 5 character(s) were removed. Do you want to enter another sentence (0 for no, 1 for yes)? 0

My code:

#include #include #include #define SIZE 100 int isPalindrome(char inputString[]) { int flag = 0; int i = 0; int length; length = strlen(inputString); int last = length - 1; int reverse[SIZE]; for (i = 0; i < length; i++) { reverse[i] = inputString[last]; last--; } for (i = 0; inputString[i] != '\0'; i++) { if (inputString[i] != reverse[i]) { return 0; } } return 1; } void ignoreNonLetters(char inputString[]) { int count = 0; int i = 0; int length; length = strlen(inputString); for (i = 0; i < length; i++) { if (isalpha(inputString[i])) { inputString[count] = inputString[i]; count++; } } inputString[count] = '\0'; } int ignoreUpper(char inputString[]) { int i = 0; while (inputString[i]) { inputString[i] = tolower(inputString[i]); i++; } } int main(void) { int choice = 1; while (choice == 1) { int palindrome; char inputString[SIZE]; printf("Enter a sentence: "); gets(inputString); ignoreNonLetters(inputString); ignoreUpper(inputString); printf("%s", inputString); palindrome = isPalindrome(inputString); do { if (palindrome == 1) { printf(" The sentence is a palindrome"); } else { printf(" This sentence is not a palindrome"); } printf(" Do you want to enter another sentence (0 for no, 1 for yes) ? : "); scanf_s("%d", &choice); } while (getchar() != ' '); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!