I did something simliar.. Check this out:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define TRUE 1
#define FALSE 0
#define SIZE 256
int paliTest(char[], int high, int low); // Defines the function (accepts input
// of string, high-size of string and
// and low -beginning of array
char sopal[SIZE]; //these are temporary arrays that store
// temporary char data
char lowpal[SIZE];
int a;
int i;
int main()
{
char str[SIZE]; //setting the size of str to SIZE
printf("Please enter a palindrome\n"); // Prompts user for palidrome
scanf("%s",&str); // scans it into a character array called string
int high = 0; // sets high to 0
int low = 0; // sets low to 0
int i = 0; // sets i to 0
high=strlen(str)-1; // sets high to the number of indexes in str -1 to account
// for /01 character at end
for(i=0,a=0;i<high;i++) //for test while i is less than high (which is defined
{ //above
if(isalnum(str[i]))// if str[index] is a alphanumeric character copy it
// to a temporary character array
{
sopal[a]=str[i];
a++; // increment the index of the temporary character array
}
}
for(i=0,a=0;i<high;i++) //for test while i is less than high
{
str[i] = tolower(sopal[i]); //copies back the string into character array str
// while converting any characters from upper case
// to lower
}
if (paliTest(str,high,low)) // If the function is true
{
printf("\nYou entered a palindrome.\n"); //display palindrome detected
}
else //else
{
printf("\nYou did not enter a palindrome.\n"); // string is not a palindrome
}
system("pause"); // pauses screen so user can read
return 0;
}
int paliTest(char str[],int low,int high) // Defines the function (accepts input
// of string, high-size of string and
// and low -beginning of array
{
if(str[low]==str[high]) // if the first and last element of the array is equal
// return true
{
paliTest(str,low+1,high-1);//Recursion which then compares the next two elements
// of the array on either end
return TRUE; // returns true which indicates that it is a palindrome
}
else // else
{
return FALSE; // returns false which indicates its not a palindrome
}
}