/* File: pali2.c Checks if a string is a palindrome. */ #include #include"genlib.h" #include"simpio.h" #include"strlib.h" /* Function Prototype */ bool IsPalindrome(string str) ; main() { string str ; printf("This program checks for palindromes.\n") ; printf("End the program by entering a blank line.\n") ; while (TRUE) { printf("String: ") ; str = GetLine() ; if ( StringEqual(str, "") ) break ; if ( IsPalindrome(str) ) { printf("'%s' is a palindrome.\n", str) ; } else { printf("'%s' is not a palindrome.\n", str) ; } } /* end while */ } /* Function: IsPalindrome */ bool IsPalindrome(string str) { char front, back ; int head, tail ; head = 0 ; tail = StringLength(str) - 1 ; while (head < tail) { front = IthChar(str, head) ; back = IthChar(str, tail) ; if (front != back) return(FALSE) ; head++ ; tail-- ; } return(TRUE) ; }