Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Upper Case to Lower Case and vise-versa in C

    How do I convert from an Uppercase letter to a Lowercase letter in C??

    Thanks for the help,
    Lippy

  • #2
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    a quick google search for C "upper case" "lower case" yielded:

    tolower

    and

    toupper

  • #3
    New Coder
    Join Date
    Nov 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey this is great, thanks

    anyone wouldn't by any chance know how to test to see if the letter is either upper case or lower case?

    Lippy

  • #4
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wouldn't it be as simple as:

    if (toupper((int)mychar) == (int)mychar) {
    // then it's upper case
    } else {
    // then it's lower case
    }

    ?

    Edit: I can't remember if integer type conversion from characters is implicit in C, so I edited it to add the integer typecasting
    Last edited by cfc; 01-31-2005 at 06:17 AM.

  • #5
    New Coder
    Join Date
    Nov 2004
    Location
    Netherlands
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A quicker way to do that would be to create a definition that tests the range, in example:

    Code:
    #define IS_UPPER(c) ((c >= 'A') && (c <= 'Z'))
    #define IS_LOWER(c) ((c >= 'a') && (c <= 'z'))
    
    char input = getchar();
    
    if(IS_UPPER(input)) puts("Entered character is upper case");
    else if(IS_LOWER(input)) puts("Entered character is lower case");
    else puts("Entered character is not a letter");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •