hi everybody
question: Can anyone help me out to make a program that checks a string for being a palindrome or not
I only want to get the logic, so that I could try it myself
thanx in advance
bye
This is a discussion on Palindrome within the C Programming forums, part of the General Programming Boards category; hi everybody question: Can anyone help me out to make a program that checks a string for being a palindrome ...
hi everybody
question: Can anyone help me out to make a program that checks a string for being a palindrome or not
I only want to get the logic, so that I could try it myself
thanx in advance
bye
> I only want to get the logic, so that I could try it myself
Compare the first letter with the last letter
If they match, move in one letter from each end and repeat
If you meet in the middle, and its still equal, its a palindrome
If you really want to be masochistic, you can push all the letters in a stack pop them all off into a new stirng and then use strcmp. If its == 0, its a palindrome
DrakkenKorin
Get off my Intarweb!!!!
Here's one way of doing it.....
Extra brownie points if you understand it...... lol
This was written by richard heathfield,one of the authors of c unleashed.... enjoy....
Code:#include <stdio.h> #include <string.h> #include <ctype.h> #define p void #define a sizeof #define l char #define i return #define n int #define d size_t #define r if #define o while #define m else #define e for #define ob putchar #define fu strlen #define sc isalpha #define at tolower #define ed fgets #define cp printf #define ro strchr #define gr main #define am stdin n c(l*s){n k= 0;r(s){d x =fu (s) ;r(x>1) {l*t=s, *u=s+x- 1;k=1;o (k&&t<u ){r(sc( *t)){r( sc(*u)) {r(at( *t)!=at( *u) ){k =0; }m{ ++t;--u;}}m{-- u;}}m{++t;}}}} i k ;}n gr( p){ l b [01 <<1 <<1 <<1 <<1 <<1 <<1 <<1 <<1 <<1 ],* z,*s=" adeil" "mnoprst.\n"; n f[]={00,01<<1 <<1,(1<<1<<1<<1 )|( 1<< 1)| 1}, v[] ={0 ,(1<<1<<1)|(1<< 1)|1,1<<1<<1<<1 ,(1 <<1 <<01 <<1 )|(01 <<1 <<1 )} ,q[ ]={ (1 <<1 )&1 ,1 <<1 >>1 ,1 >>1 ,(1 << 1<< 1<< 1) |1, 1<< 01<<1 >>1>>1,(1<<1 <<1 )|( 1<< 1>> 1), 1<< 1<< 1,( 1<< 1<< 1)| (01 <<1 )|1 ,01 <<1 ,(1<<1<<1<<1 )|(1<<01),1 <<1 <<1 <<1 ,(1 <<1 <<1 )|1 <<1 ,(1 <<1 )|1,(1<< 1<< 1<< 1)| (01 <<1 <<1 )|1 ,(1 <<1 <<1 <<1)|(1<< 1<< 1)| (01 <<1 )}; d y ;o( ed( b,a (b) ,am )){ {z= ro( b,1 *1* '\n');}if( z){ *z= 00;} {cp( "%s", b);}e (y=0;1 *y<a f /a( 1[f ]); y++ )ob (y[f][ s]) ;r( !c(b ))e (y= 0; y<a v/a 1[v ];y ++) ob(01*y[v][s]);e (y=0/1*1/1<<1<<1 <<1 ;y< a q /a 1[q] ;y++)ob (y[ q][ s]) ;}i 0>>1<<0>>1<< 1*1/(1<<1<<01);}
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Gee, does that code really work? I'll have to try when I get home
PS: What does obfuscated mean?
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
That code Stoned Coder posted is the very definition of obfuscated (to make so difficult/confusing its hard to understand).
And those define's aren't kidding!
DrakkenKorin
Get off my Intarweb!!!!