Article View: alt.comp.lang.learn.c-c++
Article #148Re: C++ problem - help
From: JHill
Date: Mon, 05 Apr 1999 00:00
Date: Mon, 05 Apr 1999 00:00
73 lines
2476 bytes
2476 bytes
Vic,
You should just copy the input-string to some temp-string.
Invert the input-string and just do a strcmp(input-string, temp-string)
If strcmp returns zero, you have your palindrome. Be sure to convert your
input to all upper or lower case.
Victor <bushmills@tesco.net> wrote in message
news:7eatvr$p1g$1@barcode.tesco.net...
> I have been asked to design a project to determine whether a word is a
> palindrome or not (btw a plaindrome is a word that is the same backwards
ie
> noon).
>
> I have been able to run the program successfully with some words but it
> doesn't seem to like the word 'deer' and other words with the same middle
> letters. It thinks that it is a palindrome which is not true.
>
> Could somebody help please.
>
> Thanks for your time . . .
>
>
>
> #include <condefs.h>
> #include "Project1io.h"
> #pragma hdrstop
>
>
>
file://---------------------------------------------------------------------
-----
> -
> USELIB("Project1io.LIB");
>
file://---------------------------------------------------------------------
-----
> -
> #pragma argsused
> int main(int argc, char **argv)
> {
> int Front;
> int Back;
> char Palindrome;
> AnsiString InputString;
> InputString = ReadStringPr("Enter your non-empty string for testing");
> Front = 1;
> Back = Length(InputString);
> while (Front < Back)
> {
> if (InputString[Front] == InputString[Back])
> Palindrome = true;
> else
> Palindrome = false;
> Front = Front + 1;
> Back = Back - 1;
> }
> if (Palindrome == true)
> WriteString("Yes, it is a palindrome");
> else
> WriteString("No it is not a palindrome");
>
> getchar();
> return 0;
> }
>
>
>
>
>
Technical Details
Message-ID:
<457cf$f2328.1d2@ineter.edgewater.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7eatvr$p1g$1@barcode.tesco.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114592,61f8664269971e91 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,61f8664269971e91 X-Google-Attributes: gid109fba,public X-Google-Thread: 10d4ba,61f8664269971e91 X-Google-Attributes: gid10d4ba,public From: "JHill" <jhill@edgewater.com> Subject: Re: C++ problem - help Date: 1999/04/05 Message-ID: <457cf$f2328.1d2@ineter.edgewater.com> X-Deja-AN: 462968966 References: <7eatvr$p1g$1@barcode.tesco.net> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-MSMail-Priority: Normal Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++