Someone please help

This is a discussion on Someone please help within the C++ Programming forums, part of the General Programming Boards category; How would I take a lowercase char and make it uppercase using the ASCII table?...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    Someone please help

    How would I take a lowercase char and make it uppercase using the ASCII table?

  2. #2
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    Code:
    char c = 'a';
    toupper(c);
    cout<<c<<endl;
    That should print A to the screen, not a. Be sure to include ctype.h
    pointer = NULL

  3. #3
    Unregistered
    Guest
    If your going to use the Ascii table you could understand that
    a lower case char and with 0x5f will convert a lower case to an upper case.

    example:
    char letter = 'a';
    letter = letter & 0x5f;
    cout<<letter<<endl;

    and you can conver upper to lower by
    letter = letter | 0x20;


    basically all you are doing it flipping the sixth bit of the ascii code.

  4. #4
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    Bit twiddling hurts portability, unless you plan to use the program only on your own computer it's really best to use the 'one size fits all' functions. Though knowing how to play with bits is nice to know.
    pointer = NULL

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    Won't bit flipping mess with characters that aren't letters?
    All generalizations are false

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21