Thread: Uppercase and lowercase

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    59

    Uppercase and lowercase

    Okay a part of the program I have to write has to switch "one" lowercase letter and make it uppercase and vice versa. I can't use strings or anything more advanced then a begginers c++. I don't know why, he likes to be a real pain sometimes. The only thing I can think of is 54 if statements.
    I've also been told I can do it via ASCII values but I can't seem to figure that out. unless somehow you store the ascii value of every letter but that would be the same amount of work. Any ideas anyone?

    if (letter == 'A')
    letter = 'a'
    if (letter == 'a')
    letter = 'A'
    Etc..

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    you could use something like this
    Code:
    int main()
    {
                 char str[10];
            int i, delt ='a' -'A';
    
                   while (str[i]){
    		if ((str[i] >='a') && (str[i] <='z'))
    		str[i] -=delt; /*convert to upper case*/
    		i++;
                          }
    }
    Thats much of your program but it will not work as it is, you have to figure out the rest.
    When no one helps you out. Call google();

  3. #3
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    Quote Originally Posted by StarOrbs
    I don't know why, he likes to be a real pain sometimes.
    Probably because he's providing you a learning experience in logic/design.

    Study the ascii chart a bit and you'll find a pattern. Pay particular attention to the binary values of letters chars A-Z and compare them to chars a-z. When you note the difference, determine what simple operation will change lower to upper and upper to lower regardless of its value.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Can you use the islower/isupper/tolower/toupper functions?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Why not cast to an int (int)variable, check the int value, if it's between X and Y (where X is lowercase a and Y is lowercase z) than do toupper(), and if it's between Z and Q (where Z is uppercase a and Q is uppercase z) than do tolower()?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting uppercase and lowercase letters in a text
    By Tintu in forum C Programming
    Replies: 2
    Last Post: 02-06-2008, 10:15 PM
  2. how to detect a lowercase or uppercase char?
    By Axel in forum C Programming
    Replies: 5
    Last Post: 09-04-2005, 12:28 PM
  3. Replies: 14
    Last Post: 06-06-2004, 03:51 PM
  4. Uppercase & Lowercase
    By Dennis in forum C Programming
    Replies: 2
    Last Post: 11-14-2002, 08:07 AM
  5. C++ newbie..convert string from lowercase to uppercase
    By wireless in forum C++ Programming
    Replies: 5
    Last Post: 02-25-2002, 08:49 PM