Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How do you point to a const char array with the name in an array? (http://www.go4expert.com/forums/const-char-array-array-t28907/)

dfansler 17Aug2012 22:13

How do you point to a const char array with the name in an array?
 
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

debugEnthu 18Aug2012 17:15

Re: How do you point to a const char array with the name in an array?
 
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

dfansler 18Aug2012 18:37

Re: How do you point to a const char array with the name in an array?
 
opps - I am writing in C.
Thanks,
David


All times are GMT +5.5. The time now is 08:33.