Converting a hex string to hex

This is a discussion on Converting a hex string to hex within the C Programming forums, part of the General Programming Boards category; Hi, I'm trying to write a function to decode HTML encoded ASCII. I was just wondering if there is an ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230

    Converting a hex string to hex

    Hi, I'm trying to write a function to decode HTML encoded ASCII. I was just wondering if there is an easy method to convert a hex value in a string to a hex value.

    i.e: "x20" to 0x20

    or: "20" to 0x20

    This will drastically simplify a function to convert the HTML encoded characters to their ASCII equivalent. If I can't do it like this the only other way I can think of is to manually write out each counterpart in a huge switch statement i.e:

    Code:
    int x = 0;
    switch (string) {
       case "20":
       x = 32;
    ...
    ^ Which is obviously not valid code but you get the idea :P

    Then casting the integer to a character and replacing it in the string.

    Thanks!
    Last edited by pobri19; 05-06-2010 at 07:08 AM.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why not use %x with *scanf?

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Quote Originally Posted by tabstop View Post
    Why not use %x with *scanf?
    Because it's not a string coming from stdin, it's a string being returned from a HTTP socket connection.

    Can I still use it?
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by pobri19 View Post
    Because it's not a string coming from stdin, it's a string being returned from a HTTP socket connection.

    Can I still use it?
    Well, yes. There is a version of scanf that reads from stdin, a version that reads from any FILE*, and a version that reads from a string, and some other various versions as well. (That's what my * was referencing in the post.)

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Quote Originally Posted by tabstop View Post
    Well, yes. There is a version of scanf that reads from stdin, a version that reads from any FILE*, and a version that reads from a string, and some other various versions as well. (That's what my * was referencing in the post.)
    I figured that * was placed there for a reason Google yields no results. Are you saying using the address of the function for some reason? Mind pointing me in the right direction or a bit of an explanation? Thank you Tabstop
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  6. #6
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Never mind, sscanf Thanks tabstop.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    How about typing "man scanf" into Google, and clicking "I'm Feeling Lucky"?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  4. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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