Processing Strings as Character Arrays – Part II

Now that we have the helper function convertToCanonical() done, we are now ready to write the function testForPalindrome. It should take 1 argument: testStr, which it will analyze to determine whether it is a valid palindrome. This function should return a boolean value: true if testStr is an palindrome, else false.

testForPalindrome()'s job should be very easy because we have convertToCanonical(). However, because convertToCanonical() modifies it's argument, the caller is responsible for passing in a copy if it wishes to keep the original unchanged--which we do! So, testForPalindrome() should allocate a new char array (use the constant MAX_STR to dimension this, too), and copy the string from its input argument into this local array. Copying the string is eally easy using the library function strcpy() (look it up in man).

After calling convertToCanonical() with the temporary copy, you just have to manually check the converted string for "palindrome-ness", by comparing the first char against the last char, second against the next-to-last, etc.

After the test is complete, return true if the text was a palindrome, false otherwise.