#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void checkPal(char*);
int length(char *);
int main()
{
char response[35];
int result2;
char *res;
res = &response[0];
printf("Please enter a string to test if it is a palindrome:");
gets(response);
checkPal(res);
system("pause");
return 0;
}
int length(char *string)
{
int count = 0;
while( *(string + count) != '\0')
count++;
return count;
}
void checkPal(char * string) //function will reverse string accepted then perform comparison to see if string is Palindrome.
{
int len, c, result, i;
char *begin, *end, temp;
char string2[50];
len = length(string);
begin = string;
end = string;
i=0;
strncpy(string2,string,len);
string2[len] = '\0';
for (c = 0; c < len - 1; c++)
end++;
for (c = 0; c < len/2; c++)
{
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
result = strcmp(string2,string);
if(result == 0)
{
printf("Palindrome Found: %s %s",string2,string);
}
else
{
printf("The string entered was not a Palindrome: %s %s",string,string2);
}
}