#include #include #include #include #define MAX_STR_LEN 80 typedef enum { false
ID: 3659495 • Letter: #
Question
#include #include #include #include #define MAX_STR_LEN 80 typedef enum { false = 0, true } bool; void erase(char *, size_t); bool isPalindrome(const char *, const char *); char in[MAX_STR_LEN]; int main(int argc, char *argv[]) { size_t x; while (1) { printf("> "); fgets(in,MAX_STR_LEN,stdin); *(strchr(in,' ')) = ''; for (x = 0; x < strlen(in); ) { in[x] = tolower((int)in[x]); if (isspace((int)in[x]) || ispunct((int)in[x])) { erase(in, x); } else { x++; } } printf(""%s" is ",in); if (isPalindrome(in, in + strlen(in) - 1) == false) { printf("not "); } printf("a palindrome. "); } return 0; } bool isPalindrome(const char *p, const char *q) { if (q < p) return true; if (*q != *p) return false; return isPalindrome(p + 1, q - 1); } void erase(char *s, size_t x) { memmove(&s[x], &s[x+1], strlen(s) - x); }Explanation / Answer
A simpler Code :: #include #include #include int isPalindrome( char *s ); int main ( void ) { int i = 0; int ch; char s[100]; while ((ch = getchar()) != (' ')) { if (isalpha(ch)) { ch = toupper(ch); s[i] = ch; i++; } } s[i]=''; if ( isPalindrome(s) == 1) { printf("Yes, is a palindrome. "); } else { printf("No, not a palindrome. "); } return 0; } int isPalindrome( char *s ) { int i = strlen(s)-1; int j = 0; while (jRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.