Thread: Upper or Lower...Bitmask and bitwise operators

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    6

    Upper or Lower...Bitmask and bitwise operators

    I'm trying to write a program that will let the user input as many
    characters as they want. The program will then check if the characters are upper case or lower case. If the program detects a lower case letter in the input stream the program will print out the letter in char type and its hex number. When it encounters EOF and all of the letters entered are upper case the program will print "All letters entered are upper case" and the program will also count all the letters entered this number will also be displayed. I am really new to programming please have patience with me.

    This is my code


    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
        char myChar;
        
        do
        {
          myChar = getchar();
          printf("%02x ",myChar); // this is here to help debugging
          
          if(myChar == EOF) // if get user enters an EOF or the EOF is reached
             {
                printf("All are caps\n");
                // print  number of letters entered 
                // break out of loop and end program  
             }   
          
        }
        while(((myChar&0x20) == 0)); 
        {
              printf("\n");
              printf("entered LOWER CASE = %c \n",myChar);
              printf("The hex value is = %x \n",myChar); // hex value of lower case letter
                                    
        }
      system("pause");
      return 0;
    }

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    EOF is a constant which is an integer

    So myChar needs to be declared as an int.

    Some functions which may be usefull to you:
    Code:
    #include <ctype.h>
    
    int isupper(int c);
    int islower(int c);
    Fact - Beethoven wrote his first symphony in C

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    Can I ask what your logic is with this part?
    Code:
    do
    {
        ....
    }
    while (((myChar&0x20) == 0));
    Fact - Beethoven wrote his first symphony in C

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. convert from upper to lower
    By tost in forum C Programming
    Replies: 18
    Last Post: 02-05-2013, 01:56 AM
  2. to lower or to upper that is the question!
    By verbity in forum C++ Programming
    Replies: 20
    Last Post: 04-25-2007, 06:42 PM
  3. Lower to Upper
    By Krush in forum C Programming
    Replies: 13
    Last Post: 11-19-2002, 10:14 PM
  4. string converting upper/lower
    By jlamn in forum C Programming
    Replies: 9
    Last Post: 09-24-2002, 06:01 PM
  5. lower to upper
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-29-2002, 07:50 PM

Tags for this Thread