🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #147

Re: C++ problem - help

#147
From: Krzysztof Parzyszek
Date: Mon, 05 Apr 1999 00:00
37 lines
1913 bytes
> #pragma argsused
> int main(int argc, char **argv)

if you never want to use main's arguments, then declare it as

int main()


>     Front = 1;

I might be wrong on this one, but I think that
AnsiString is indexed from 0.


>     while (Front < Back)
>       {
>         if (InputString[Front] == InputString[Back])
>           Palindrome = true;
>         else
>         Palindrome = false;
>         Front = Front + 1;
>         Back = Back - 1;
>       }

Look what you are doing. You are setting the Palindrome flag
every time you compare the elements of InputString.
Thus the procedure remembers only the result of the last
comparison. So if the word have two middle letters identical
(assuming it has even # of letters) then the procedure will
think it is a palindrome.
(Note, that the middle letters are checked last.)

A word is NOT a palindrome if there is at least one pair of
corresponding characters that don't match. So you should
stop checking when you encounter the first mismatch.

Chris
Technical Details
Message-ID: <3709101F.A07D3D99@iname.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7eatvr$p1g$1@barcode.tesco.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,61f8664269971e91
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 109fba,61f8664269971e91
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,61f8664269971e91
X-Google-Attributes: gid114592,public
From: Krzysztof Parzyszek <hektor@iname.com>
Subject: Re: C++ problem - help
Date: 1999/04/05
Message-ID: <3709101F.A07D3D99@iname.com>
X-Deja-AN: 462968965
Content-Transfer-Encoding: 7bit
References: <7eatvr$p1g$1@barcode.tesco.net>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@tpsa.pl
X-Trace: news.tpnet.pl 923340893 212.160.52.146 (Mon, 05 Apr 1999 21:34:53 MET DST)
Organization: TPNET - http://www.tpnet.pl
MIME-Version: 1.0
NNTP-Posting-Date: Mon, 05 Apr 1999 21:34:53 MET DST
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++