Thread: I want to create a char array

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    1

    Lightbulb I want to create a char array

    Dear frd
    I want to create a char array that have values in form of
    0x31,0x38 etc all pure hex from string.
    string is like "3703031313132.."
    i have to take two char from string and save as one char in array
    like first take 37 and store as 0x37 in array
    pls help me


  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Here's some information to get you started. If you take the ASCII number in your string, and subtract 30 from it, you will get the hex value you are looking for.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Code:
    char str[] = {0x37, 0x38, etc};
    char firstchar = str[0];

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char *s, array[] = "Hello World!";
    for( s = array; s && *s; s++ )
        printf("0x%x ", *s );
    Or did you mean you wanted the string new array to be something like:
    Code:
    char newarray[] = "0x48 0x65 0x6c 0x6c 0x6f 0x20 0x57 0x6f 0x72 0x6c 0x64 0x21";
    If so, if you don't want spaces between the hex digits, and you don't want the 0x, just create a string twice the size of the length of the other string, plus one, and stick them in there.

    I'll leave that as an exercise for the reader, since it's fairly easy, and we have to leave something for you to do...

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM