![]() |
|
#1
|
|||
|
|||
Palindrome code errorI want to create a program determines whether an input string is a palindrome.
I want to get a output result like below if I type a sting "zyaxwvxbyz", "The sting is not a palindrome: the character in position 2 is 'a', while the character in position 7 is 'b'." my code is below could you advise for me what is wrong? CPP / C++ / C Code:
Last edited by LuciWiz : 25-Apr-2009 at 19:09.
Reason: Please insert your C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
||||
|
||||
Re: palindrome code errorCPP / C++ / C Code:
__________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#3
|
|||
|
|||
Re: palindrome code errorbecause I wanna find the position and mismatch letters.
|
|
#4
|
|||
|
|||
Re: Palindrome code errorYour function
CPP / C++ / C Code:
If you want to find out whether the string is a pallindrome or not as well as determine the non matching characters, may be you can do something like this: CPP / C++ / C Code:
While in your function CPP / C++ / C Code:
In the else part CPP / C++ / C Code:
|
|
#5
|
||||
|
||||
Re: Palindrome code errorIt seems that your original intent was to modify the string with zeroes in the IsPalindrome() function [which will not happen, userInput is only a copy in that fuction], and then loop again [once back in main] to find the zeroed entries.
Why loop twice? Plus, as WaltP indicated, why alter the string? What if the string already contains other zeroes? Zalezog is right that you don't know the letters, and as an alternative to his suggestions, this is yet another way that it can be done by just getting the index points where the problem occurred. (see all the comments) CPP / C++ / C Code:
Code:
Code:
Code:
EDIT: If you really want to get fancy, it would be nifty to eliminate all the white spaces [or intelligently ignore them] and then you could verify that a phrase such as this: "A man a plan a canal panama" ...is also a palindrome! But I'll leave that as an "extra curricular" exercise. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#6
|
|||
|
|||
Re: Palindrome code errorthank you I got it
|
|
#7
|
|||
|
|||
Re: Palindrome code errorYOU CAN USE THIS CODE IF YOU WISH.....
CPP / C++ / C Code:
Last edited by admin : 26-May-2009 at 04:15.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#8
|
|||
|
|||
Re: Palindrome code errorQuote:
Here could be a "C++ed" version of what you posted. CPP / C++ / C Code:
It's usually a good idea to compile and test if what you post works. It reduces a whole lot of frustration from those people who might try out your code. |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| RedHat Linux memory problem | nzmose | Computer Software Forum - Linux | 1 | 02-Aug-2008 10:07 |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 11:13 |
| Major newbie problem | cynack | MS Visual C++ / MFC Forum | 1 | 08-Apr-2007 12:25 |
| functions seems not to exit from a certain code block | jaro | C Programming Language | 3 | 22-Mar-2006 00:08 |
| Can enum have same name as class? | crystalattice | C++ Forum | 3 | 08-Dec-2004 17:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The