Lab 5: Palindromes

Introduction

This week, we will practice with arrays and strings. You will be required to read in a string of characters from standard input and determine whether the string is a palindrome or not.

Background

A palindrome is a sequence of characters that reads the same forward as backwards. For example, the words "radar," "racecar," and "madam" are palindromes.

For the purposes of this lab, all spaces and punctuation must match exactly, forwards and backwards. For example, "race car" will not be considered a palindrome. However, you should ignore capitalization when determining if a string is a palindrome. Thus, "Racecar" will be considered a palindrome. Numbers and other symbols are permitted as long as they match exactly, forwards and backwards.

When using printf() to print out a string of characters, those characters must be terminated with a null character ('\0'), or there is a risk of a segmentation fault.

Lab Exercise

For this lab, you must read in characters one at a time from standard input using the getchar() function. You should only read the first 1023 characters as input. If the input is longer than that, you may ignore it. This stipulation is provided so that you can use a fixed size array. For normal input that does not exceed the limit, you should read until you hit either an EOF or a newline character.

Once you have read the input, you should test to see whether or not it is a palindrome. You must perform the necessary case conversion yourself.

Then, you should print a message saying whether or not the string is a palindrome. Your output should match the formatting given in the next section.

You are only permitted to call two library functions in this program: getchar() and printf().

You must also include a makefile with a clean command in it.

Sample Execution

Below is sample output for an execution of the program in which the user enters UFOtofu (a palindrome). User input is shown in green.

Enter a string: UFOtofu
The string "UFOtofu" is a palindrome.

Below is sample output for an execution of the program in which the user enters real lager (a non-palindrome). User input is shown in green.

Enter a string: real lager
The string "real lager" is not a palindrome.

Turn In

Zip the contents of your lab directory, including the makefile and the source C file. Upload this zip file to Brightspace. Do not include any object files or executables. Running the make command must compile the required C source code file and generate an executable named palindrome.

All work must be done individually. Never look at someone else's code. Please refer to the course policies if you have any questions about academic integrity. If you have trouble with the assignment, I am always available for assistance.