/* File: pali1.c Checks if a string is a palindrome. */ #include #include"genlib.h" #include"simpio.h" #include"strlib.h" /* Function Prototypes */ 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) { int i, n ; char front, back ; n = StringLength(str) ; for (i = 0 ; i < n/2 ; i++ ) { front = IthChar(str, i) ; back = IthChar(str, n - i - 1) ; if (front != back) return(FALSE) ; } return(TRUE) ; }