1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you point to a const char array with the name in an array?

Discussion in 'C' started by dfansler, Aug 17, 2012.

  1. dfansler

    dfansler New Member

    Joined:
    Aug 17, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    I am doing some work with a LCD graphic display and a microcontroller. I have defined the alphabet in a series of constant char arrays that tell me what bits to turn on or off to display that character - ie. for '0' (0x30)

    const char CS22PT_0x30[122] ={18,40,
    0x00,0x00,0x00,0x00,x00,0x10, etc.........
    }
    The first two numbers are the x and y size of the character. I call this array by
    char far *name
    name = &CS22PT_0x30;
    Display_Graphic(name);

    And this works. As long as I know ahead of time what the name of the const char array I am calling is.

    So the next step was to take a char array containing the string I want to display and determine which const char array to call on the fly rather than hard coding it in.

    What I have so far is an array predfined as
    char text_1[] = {"Night's Beautiful Daughter"};

    I set a pointer to the array
    char *t_to_d;
    t_to_d = &text_1[0];

    call a function that uses that pointer and the name of the font to use
    write_text(t_to_d,font_22)

    font_22 was previously defined as
    char font_22[]={"CS22PT"};

    the write_text fucntion then converts (starting with the first character of text_1[0]) into a hex value that is cat onto the font name. ie Since the first character in text_1 is 'N' which is 0x4e in hex, I get an array that contains CS22PT_0x4e

    FINALLY I can ask the question!!
    How do I use the string "CS22PT_0x4e" in the array to point to the const char CS22PT_0x4e so I can get the data out of const char CS22PT_0x4e?

    Thanks,
    David
     
  2. debugEnthu

    debugEnthu New Member

    Joined:
    Jul 5, 2012
    Messages:
    11
    Likes Received:
    3
    Trophy Points:
    0
    Hi,

    Which language are u using??/

    In case you are using C++ you canuse STL map containers

    map<unsigned int, char *> mymap.

    Here key (unsigned int) would be hex representation of character...n your example - 0x4e
     
  3. dfansler

    dfansler New Member

    Joined:
    Aug 17, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    opps - I am writing in C.
    Thanks,
    David
     

Share This Page