Article View: alt.comp.lang.learn.c-c++
Article #151Re: C++ problem - help
From: Sunil Rao
Date: Tue, 06 Apr 1999 00:00
Date: Tue, 06 Apr 1999 00:00
25 lines
1576 bytes
1576 bytes
Eric Tetz <etetz@accolade.com> wrote, and I reply...
>bool IsPalindrome (char * string)
>{
> for (char * first = string,
> char * last = string + strlen (string) - 1;
> first <= last;
> first++, last--)
> {
> if (*first != *last)
> return false;
> }
>
> return true;
>}
You might have a slight problem here if the string is empty - there's no
guarantee that last will point to a valid location in memory if this is
the case.
--
{ Sunil Rao }
"Is there any light more becoming than that, low and richly tinted, that comes
subdued through the mists of sunshine?"
-- J Sheridan Le Fanu
Technical Details
Message-ID:
<VpgY5PBFdUC3EwV7@raos.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7eatvr$p1g$1@barcode.tesco.net> <01be800c$9ae4c780$5f064fce@TETZ>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,61f8664269971e91 X-Google-Attributes: gid109fba,public X-Google-Thread: 10d4ba,61f8664269971e91 X-Google-Attributes: gid10d4ba,public X-Google-Thread: 114592,61f8664269971e91 X-Google-Attributes: gid114592,public From: Sunil Rao <sunil.rao@ic.ac.uk> Subject: Re: C++ problem - help Date: 1999/04/06 Message-ID: <VpgY5PBFdUC3EwV7@raos.demon.co.uk> X-Deja-AN: 463044569 Distribution: world X-NNTP-Posting-Host: raos.demon.co.uk:193.237.25.118 References: <7eatvr$p1g$1@barcode.tesco.net> <01be800c$9ae4c780$5f064fce@TETZ> X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 923355295 nnrp-11:14216 NO-IDENT raos.demon.co.uk:193.237.25.118 Organization: Sunil Rao's Wonder Machine MIME-Version: 1.0 Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++