We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm having serious problem with the following code:
unsigned char code * Progtxtstring_ENG[] = { "PROGRAM", "SYSTEM" }; unsigned char code * pMenu; //User selected English pMenu = Progtxtstring_ENG; //Why doesn't this work, it just get garbage out: printf("%s",pMenu[0]); // This line below works printf("%s",Progtxtstring_SWE[0])
"I want to use the pMenu just as I use the Progtxtstring_ENG. I want to switch between arrays of pointers so I can point to different language." Why confuse yourself with an extra pointer, then? Why not just use a 2-dimensional array?
Why not just use a 2-dimensional array? Because true 2-dimensional arrays essentially don't exist in C? You can define arrays-of-arrays, sure, by you can't do very much with them that wouldn't silently turn them into a pointer-to-array. Or because he would need a dynamic array for this to work, with more than one unknown dimensions, found in some other place than the outer-most indexing level:
char string_table[n_tables][/*unknown*/][/*unknown*/]
"Or because he would need a dynamic array for this to work" Really? I'd assumed there'd be a fixed number of languages, and a fixed number of entries in each menu - especially as he's storing them in code space:
char menu[NUM_LANGUAGES][NUM_ENTRIES]
"Because true 2-dimensional arrays essentially don't exist in C? You can define arrays-of-arrays, sure, by you can't do very much with them that wouldn't silently turn them into a pointer-to-array." But, surely, the same could be said of 1-dimensional arrays - you can't do much with them, either, that doesn't silently turn them into pointers? After all, the offset operator [] can be applied to any pointer - whether or not it was defined as an array!