Question: Write a C program named ispalindrome.c which insists on having one argument (i.e. argc == 2). It checks its argument string to see whether it's

Write a C program named "ispalindrome.c" which insists on having one argument (i.e. argc == 2). It checks its argument string to see whether it's a palindrome, and exits with exit status 0 if it is a palindrome, or 1 if it is not. A "palindrome" is a coherent phrase which consists of the same letters and digits forwards and backwards, although the spacing and capitalization may be different (in fact, all non-alphanumeric characters are irrelevant). Some examples:
Madam, I'm Adam.
A man, a plan, a canal, Panama.
Doc, note: I dissent! A fast never prevents a fatness. I diet on cod.
Won 12 tons? Not 21 now.
Implementation technique for ispalindrome.c: Start a pointer-to-char at the beginning of the string and another pointer-to-char at the end of the string. (Find the end of the string with a simple linear search to find the zero byte.) The pointer which started at the beginning of the string gets incremented and the pointer which started at the end of the string gets decremented, until they meet or pass.
So your loop will look something like "while (p < q)".
Note: Since this exercise is about strings and pointers, you must use this pointer strategy to get the point for the lab. That is to say, your access to a character in the string has to look more like "*p" than like "s[i]". (And "*(s+i)" doesn't count as the pointer strategy, that's the same as s[i] (by definition). You have to use a pointer variable which you are stepping through the string without indexing.)
Note relevant functions available after "#include ": isalnum(c) returns whether the character c is alphanumeric (you should skip all non-alphanumeric characters in making your comparison), and tolower(c) returns a lower-case version of the character c if it's an upper-case letter (e.g. tolower('E') returns 'e'), and returns the character itself otherwise (e.g. tolower('e') returns 'e', and tolower('2') returns '2').

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!