Thread: how to detect a lowercase or uppercase char?

  1. #1
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335

    how to detect a lowercase or uppercase char?

    the tolower(char) toupper(char) functions can be used to convert a char to an upper or lower case. I wanted to use these functions together with a char array, if the character in the array is lower case then convert it to upper case. But i'm not sure how to tell if the character in the array is upper or lower case to run the appropriate function.. any ideas?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    ctype.h also contains the functions
    Code:
    int isupper(char c);
    int islower(char c);

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Testing may be unnecessary.
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main(void)
    {
       char text[] = "abc 123 DEF !@#";
       size_t i;
       puts(text);
       for (i = 0; text[i] != '\0'; ++i)
       {
          text[i] = toupper(text[i]);
       }
       puts(text);
       return 0;
    }
    
    /* my output
    abc 123 DEF !@#
    ABC 123 DEF !@#
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by sean_mackrory
    ctype.h also contains the functions
    Code:
    int isupper(char c);
    int islower(char c);
    Actually the parameters are int not char

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The author of C++ 5 for Dummies wasn't specific.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Yeah but the standard sure is

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  2. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  3. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  4. Change a line of text eash first char to uppercase
    By zp523444 in forum C Programming
    Replies: 17
    Last Post: 03-15-2004, 07:43 PM
  5. Extra printed stmts...why?
    By mangoz in forum C Programming
    Replies: 4
    Last Post: 12-19-2001, 07:56 AM