Thread: Need help with palindrome program

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    24

    Need help with palindrome program

    Hi,
    I'm not expecting anybody to do the work for me, I would really appreciate it if you guys could lead me in the right direction. I need to write a program in C using only #include <stdio.h> and #include <stdlib.h> to write a program that checks whether a string is a palindrome or not. The string has letters, punctation characters, and digits. Assume the string ends with a null terminator. Assume the string has no spaces and distinguish between lowercase and uppercase characters. So madam is a palindrome, but MaDam is not a palindrome.
    So the string takes at most 30 characters. What I am really confused on is what library functions I would use to determine the length of the string? And how would I distinguish between lower and uppercase characters?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > I need to write a program in C using only #include <stdio.h> and #include <stdlib.h>
    Mmmm-ok


    > What I am really confused on is what library functions I would use to determine the length of the string? And how would I distinguish between lower and uppercase characters?
    Well the obvious answer is strlen() in string.h, and isupper()/islower() in ctype.h

    Are you allowed to use them, or do you have to write your own?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User naaissus's Avatar
    Join Date
    Jan 2016
    Location
    Balkan
    Posts
    23
    With stdio only:
    Code:
    char string[] = "Does this works....";
        
    int length = 0;
    while (string[length] != '\0')
        length++;
    
    printf("Length: %d\n", length);
    
    char testChar = 's';
    if (testChar >= 'A' && testChar <= 'Z')
        printf("UpperCase\n");
        
    if (testChar >= 'a' && testChar <= 'z')
        printf("LowerCase\n");
    Last edited by naaissus; 02-13-2016 at 03:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program to check for Palindrome
    By Elias Zaguri in forum C Programming
    Replies: 7
    Last Post: 10-29-2015, 10:52 AM
  2. Palindrome Program Help!
    By kamperkid in forum C Programming
    Replies: 39
    Last Post: 12-12-2011, 09:16 PM
  3. Need help , Palindrome program
    By amigoloko in forum C++ Programming
    Replies: 9
    Last Post: 07-11-2005, 12:07 PM
  4. Palindrome program help please
    By hunter_04 in forum C++ Programming
    Replies: 7
    Last Post: 09-20-2004, 07:38 PM
  5. C++ Palindrome program help
    By hunter_04 in forum C++ Programming
    Replies: 8
    Last Post: 09-19-2004, 09:23 PM

Tags for this Thread