HI,
My goal is to write a program to test if a particular string is a palindrome (string that's spelled the same way backwards and forwards ). Here is the code but it doesn't work, it always return false, i don'tk now why, pls tell me whats wrong, thnx in advance!
Code:/* Palindrome */ #include <stdio.h> int testPalindrome( char array[] ); int main() { char string[ 6 ] = "ellle"; if ( testPalindrome( string ) == 1 ) printf( "String is a palindrome.\n " ); else if ( testPalindrome( string ) == 0 ) printf( "String is not a palindrome.\n" ); getch(); return 0; } int testPalindrome( char array[] ) { int length = 0; int i = 0; i = 0; while ( array[ i ] != '\0' ) { ++length; i++; } if ( length - 1 == 0 || length - 1 == 1 ) return 1; else if ( array[ 0 ] != array[ length - 2 ] ) return 0; else { array[ 0 ] = '\0'; array[ length - 2 ] = '\0'; for ( i = 0; i < 6; i++ ) printf( "%c", array[ i ] ); return testPalindrome( array ); } }