Question
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
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).
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. Similar to the test program, there is no output, unless there is a usage error.
(but only after you complete your "ispalindrome"! You may have to copy and modify the 'findpal' shell script to get it to run your ispalindrome in the right location.)
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.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started