We have to create a simple program to detect palindromes, mine basically does that, but now we have to modify it so it ignores case and ignores punctuation.
I modified it to ignore the case by just simply turning all letters in the string to uppercase, but i'm stuck on implementing the isalpha() function to ignore punctuation marks, any help appreciated. Cheers
Code:
#include <stdio.h>
#include <ctype.h>
int isPalindrome(char s[]);
int main (void){
char s[100];
printf("Enter string:\n"); //MAIN FUNCTION GETS THE INPUT
fgets(s, 100, stdin);
isPalindrome(s);
return 0;
}
int isPalindrome(char s[]){ //THIS FUNCTION DOES THE STRING CHECKING
int len;
int lo, hi;
for(len = 0; s[len] != '\0'; len++); //GETTING LENGTH OF STRING
lo = 0; //LO is the starting of the array
hi = len - 2; //HI is the length of the array - 2.
while(hi > lo){
s[hi] = toupper(s[hi]); //CONVERSION TO UPPERCASE
s[lo] = toupper(s[lo]);
if(s[lo] != s[hi]){ //THE CASE FOR IF IT'S NOT A PALINDROME
printf("Not a palindrome\n");
printf("%c %d %c %d\n", s[lo], lo, s[hi], hi); //DEBUGGING CHECKS
return 0;
}
hi--;
lo++;
printf("%c %d %c %d\n", s[lo], lo, s[hi], hi);
}
printf("Yes a palindrome\n");
return 0;
}