This is a palindrome checker I have made in c. It works for all inputs, whether they have punctuation or not EXCEPT when the last item is a punctuation. In this case it does not skip it and compares and then says that it is not a palindrome when in fact it is. EX(lived, devil. will not be a palindrome but lived, devil will be).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define max 180
bool is_palindrome(const char *message);
int main()
{
char message[max+1];
printf("Enter a message: ");
gets(message);
if(!*message)
{
printf("input error");
return 0;
}
if (is_palindrome(message)) printf("Palindrome\n");
else printf("Not a palindrome");
return 0;
}
bool is_palindrome(const char *message)
{
char *p, *p2;
bool palindrome = true;
p = message;
p2 = message;
for(;;)
{
while(*p)p++;
while(*p2)
{
while(!isalpha(*p)) p--;
while(!isalpha(*p2)) p2++;
if (toupper(*p) != toupper(*p2))
{
palindrome = false;
break;
}else
{
p--;
p2++;
}
}
break;
}
return palindrome;
}