Thread: Trick with strings help/questions

  1. #1
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73

    Trick with strings help/questions

    Question 1:
    Hey guys, I got a question about strings. Suppose *p points to a character in a string, say character 'A'. I have a pointer *r and I wish to point *r such that

    Code:
    *r = *p | 0x20;
    How does 'A' turn to 'a'???

    Question 2:
    Also, What should I prepare for when dealing with strings? The question above was from a past final for my C class.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    What is the ASCII value of 'A' vs. 'a', and what is the relationship of these to the value of 0x20?

    IMHO, it's a silly trick that you'll never need to do in the real world; in fact, I would view someone writing something like that to be somewhat of a software sociopath.

  3. #3
    Stressed Student :(
    Join Date
    Feb 2008
    Location
    Berkeley, CA
    Posts
    73
    So....

    'a' is 97 in decimal, in binary:

    0110 0001

    'A' is 65 in decimal, in binary:

    0100 0001

    and let's OR it with 0x20...
    thats...

    0010 0000
    0100 0001
    --------------
    0110 0001

    there we have it.
    2 of my profs this yr are scary

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Problems with strings as key in STL maps
    By all_names_taken in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:34 AM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM