Thread: Palindrome C program where capital letters dont matter

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    4

    Palindrome C program where capital letters dont matter

    Hi guys,

    Im working on a palindrome program and the internet has been quite helpfull, I have been able to write a program that almost works as I want it to work. The only thing I'm struggling with is that capital letters are not the same as normal letters in ASCII.
    I would like my program to be able to mark both 'mum' and 'Mum' as a palindrome.
    This is my code for now :

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    int main() {
        char palindroom[50];
        int lengte, i;
        int woord = 0;
    
    
        printf("Enter a string:\t");
        scanf("%s", palindroom);
    
    
        lengte = strlen(palindroom);
    
    
        for (i = 0; i < lengte; i++) {
            if (palindroom[i] != palindroom[lengte - i - 1]) {
                woord = 1;
                break;
            }
        }
    
    
        if (woord) {
            printf("%s is not a palindrome", palindroom);
        }
        else {
            printf("%s is a palindrome", palindroom);
        }
        getchar();
        return 0;
    }
    not all words are English as you can read, that's Dutch but I think you'll understand.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I would like my program to be able to mark both 'mum' and 'Mum' as a palindrome.
    Then perhaps you should be comparing the characters using the same case using something like tolower() (from ctype.h).

    Code:
     if (tolower(palindroom[i]) != tolower(palindroom[lengte - i - 1]))
    And be careful that line has a buffer underflow error when lengte is less than 2.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why capital letters in function
    By vrkiller in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2011, 01:21 PM
  2. Capital Letters?
    By MiroMage in forum C Programming
    Replies: 8
    Last Post: 11-05-2008, 04:32 PM
  3. strcmp, a problem with capital letters
    By RichardH in forum C Programming
    Replies: 11
    Last Post: 04-23-2007, 08:49 AM
  4. Capital Letters ...
    By twomers in forum C++ Programming
    Replies: 11
    Last Post: 01-11-2006, 03:10 AM
  5. check for capital letters
    By blackwyvern in forum C++ Programming
    Replies: 3
    Last Post: 01-30-2002, 10:32 PM

Tags for this Thread