#include #include #include #include #define LINESIZE 100 bool is_palindrome(char *s); int main(void) { printf("enter a line of text:\n"); char line[LINESIZE]; fgets(line, LINESIZE, stdin); char *endptr = strchr(line, '\n'); if (endptr == NULL) { printf("line too long, maximum %d\n", LINESIZE); return 1; } *endptr = '\0'; printf("input '%s'\n", line); if (is_palindrome(line)) { printf("a palindrome\n"); } else { printf("not a palindrome\n"); } } bool is_palindrome(char *s) { char *p1 = s; char *p2 = s + strlen(s) - 1; while (p1 < p2) { while (!isalnum(*p1) && (p1 < p2) ) ++p1; while (!isalnum(*p2) && (p1 < p2) ) --p2; if (p1 >= p2) { return true; } if (tolower(*p1) != tolower(*p2)) { return false; } ++p1; --p2; } return true; }