Task: Read a string, ignore case and spaces, compare from both ends and print whether it is a palindrome.
#include <stdio.h>
#include <ctype.h>
int main(void) {
char s[512], t[512];
int c, i=0, j=0;
printf("Enter a string: ");
while((c=getchar())!='\n' && c!=EOF) { if(i<511) s[i++]=(char)c; }
s[i]='\0';
for (i=0; s[i]; ++i) {
if (isalnum((unsigned char)s[i])) t[j++] = tolower((unsigned char)s[i]);
}
t[j]='\0';
int l=0, r=j-1, ok=1;
while(l<r){ if(t[l]!=t[r]){ok=0;break;} ++l; --r; }
printf("%s\n", ok ? "Palindrome" : "Not a palindrome");
return 0;
}