Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions