Code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
int pal(char *input);
int main( )
{
char *stop = "done";
char input[81];
printf("\nEnter a string of characters for palindrome verification: ");
scanf("%80s", input);
while (strcmp(input,stop) != 0)
{
printf("\n%s\n\n", input);
if (pal(input))
{
printf("Input is a palindrome\n\n");
}
else
{
printf("Input is not a palindrome");
}
printf("\n\nEnter a string of characters for palindrome verification: ");
scanf("%80s", input);
}
printf("\n******Program Terminated******\n\n");
return (EXIT_SUCCESS);
}
int pal(char *input)
{
int length = strlen(input) - 1;
int i = 0;
int j = length;
char start = input[i];
char end = input[j];
int exit = 0;
while (TRUE && (exit = 0))
{
while (isalpha(start) != 0)
{
++i;
}
while (isalpha(end) != 0)
{
--j;
}
if (i > j)
{
return (1);
}
else
{
while (isalpha(end) == 0 && isalpha(start) == 0)
{
if (start == end)
{
++i;
--j;
}
else
{
exit = 1;
}
}
}
}
return (0);
}
This is the code I've developed. I decided to try comparing characters individually, because I couldn't figure out how to reverse the string. Nevertheless, it doesn't work. Does anyone have any insights?
Thanks.
-Sean