DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Palindrome :D

07.01.2005
| 5643 views |
  • submit to reddit
        
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com

#include <stdio.h>

int isPalindromo( char *s ){
	char *s2 = s + strlen( s ) - 1;
	if( !*s )
		return 1;
	while( *s++ == *s2-- && *s );
	return !*s && *( --s ) == *( ++s2 );
}

int main( int argc, char *argv[] ){
	char s[255];

	printf( "Texto:" );
	gets( s );
	printf( "%s \n", isPalindromo( s ) ? "YES" : "NO" );

	system( "pause" );

	return 0;
}