Question: Write a complete C program that prompts the user for a single line of text and prints whether it is a palindrome, i.e., whether it's

 

Write a complete C program that prompts the user for a single line of text and prints whether it is a palindrome, i.e., whether it's ``the same'' backwards as forwards, according to the following rules:

Only letters and digits count; spaces, punctuation, etc., do not.

Case of letters is not significant ('A' and 'a' are considered the same).

The program should also print an error message if the text supplied by the user doesn't fit into the array you use to represent the input string.

Here are some sample executions (assuming you call your program palindrome and compile with make):

[bmassing@dias04]$ ./palindrome enter a line of text: abcd dcba input 'abcd dcba' a palindrome [bmassing@dias04]$ ./palindrome A man, a plan, a canal -- Panama! input 'A man, a plan, a canal -- Panama!' a palindrome [bmassing@dias04]$ ./palindrome enter a line of text: abcd 12 bcda input 'abcd 12 dcba' not a palindrome [bmassing@dias04]$ ./palindrome enter a line of text: abcd 1221 dcba input 'abcd 1221 dcba' a palindrome 

Hints:

You may find sample programs echoline-fgets.c and string-length.c helpful.

You may find library functions such as isalpha() and tolower helpful.

SAMPLE PROGRAMS

/* echoline-fgets.c * Program to get and echo line of text using fgets(). */ #include  #include  #define SIZE 80 int main(void) { printf("enter line "); char line[SIZE]; fgets(line, sizeof(line), stdin); /* was the line too long? */ char *endline = strchr(line, ' '); if (endline == NULL) { printf("line too long "); } else { *endline = '\0'; printf("line is '%s' ", line); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!