Hello Sir,
I have a problems that i am confuse
A program to find the palindrome using thsi function Pali(Sting s) S where as to check S is palin drome.
Regards
Darious.
5 replies to this topic
#1
Posted 19 April 2010 - 10:01 PM
|
|
|
#2
Posted 20 April 2010 - 12:40 AM
do you know what a palindrome is?
If you don't, it is words that are spelled the same front to back as back to front example:"deed"
So all you have to do is write a function that receives a string as parameter and then see if the last character is the same as the first letter and so on...
Post the code you have thus far and we will help... But we won't write the whole program for you...
If you don't, it is words that are spelled the same front to back as back to front example:"deed"
So all you have to do is write a function that receives a string as parameter and then see if the last character is the same as the first letter and so on...
Post the code you have thus far and we will help... But we won't write the whole program for you...
#3
Posted 20 April 2010 - 02:16 PM
Another way to do it is to reverse the original string, then compare the two string to see if they are the same or not.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#4
Posted 20 April 2010 - 05:36 PM
BOOL Pali(char * str) {
int l=strlen(str);
int h=l/2;
int i;
for (i=0; i<h; i++) {
if (str[ i]!=str[l-i-1]) return 0; //the space after the first [ is so this isn't turned into italics... lol
}
return 1;
}
I think... but I'm not sure. If it works.. happy happy!
Anyway, the point is that you only have to compare half of the string... the left half to the right half, mirrored. After all, if the first half is the mirror of the second half, then obviously, the second half is the mirror of the first. If an uneven number of chars in the string, then the middle is the same as itself (duh! This is called "identity", A ≡ A) and doesn't need to be checked.
Edited by Firebird_38, 21 April 2010 - 05:39 PM.
Fixed according to lintwurm's pwer specs
#5
Posted 21 April 2010 - 12:42 PM
Just so you know, the for loop in your function is wrong... ^_^
for (i=0; i++; i<h) is what you have, but should be: for (i=0; i<h ; i++)
and then the program runs smoothly ^_^
for (i=0; i++; i<h) is what you have, but should be: for (i=0; i<h ; i++)
and then the program runs smoothly ^_^
#6
Posted 21 April 2010 - 05:38 PM
lo. That's right. I'm not that good at C, because I don't really like it. But I shoulda done that one right, as in for x=start to finish step stepsize, same order. But Pascal has no "step", basic does (at least it did when I still used it 10 years ago). I normally use Delphi, and am not too well versed in C, since I can do all that with Delphi anyway.
But I guess this is the wrong place to say that I prefer Delphi :).
But I guess this is the wrong place to say that I prefer Delphi :).
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top










