remove punctuation in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siddharth29
    New Member
    • Mar 2014
    • 2

    #16
    Code:
    /*Write a program of palindrome using stack [implement stack using array]:
    Note: Punctuation, Capitalization, and Spaces are ignored. For Example- Poor dan is in a droop.
    
    Date : February 21,2014 */
    
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdbool.h>
    
    bool is_palindrome(const char* s)
    {
        int i = 0;
        int j = strlen(s) - 1;
        while(j >= 0)
        {
            if(!isalpha(s[i]))
            {
                ++i;
            }
            else if(!isalpha(s[j]))
            {
                --j;
            }
            else if(tolower(s[i]) != tolower(s[j]))
            {
                return false;
            }
            ++i;
            --j;
        }
        return true;
    }
    
    
    void printme(const char* s)
    {
        printf(" \" %s\" ",s);
        if(is_palindrome(s))
        {
            printf(" IS a palindrome! \n");
        }
        else
        {
            printf(" IS NOT a palindrome! \n");
        }
    }
    
    int main()
    {
        char s[] = "kajak";
        char s2[] = "Poor Dan is in a droop";
        char s3[] = "not a palindrome";
    
        printme(s);
        printme(s2);
        printme(s3);
        return 0;
    }

    Comment

    Working...