Go Down

Topic: 2 dimensional text arrays (Read 1 time) previous topic - next topic


Sep 27, 2007, 07:19 pm Last Edit: Sep 27, 2007, 07:21 pm by paulb Reason: 1
I've got a lot of text on this project and it would be handy to use a two dimensional array. It's all in progMem (flash) so maybe I'm getting into more issues with that.

Code: [Select]
// this is the string to send to the sign - put it in program memory (flash)
prog_uchar Mess1[][] PROGMEM  = {"   Some long text phrases here.   "};

prog_uchar Mess2[] PROGMEM  = { "  Some long text phrases here.    " };

prog_uchar Mess3[] PROGMEM  = {"   Some long text phrases here.  " };

It would be handy if I could do something like this

Code: [Select]
prog_uchar Mess[0][] PROGMEM  = {"   Some long text phrases here.   "};
prog_uchar Mess[1][] PROGMEM  = {"   Some long text phrases here.   "};

I get this error from the compiler.

error: declaration of 'Mess' as multidimensional array must have bounds for all dimensions except the first In function 'void loop()':

Is there a better way to do this?



It's essentially complaining that it can't figure out the array dimensions because strings don't have a predictable length.   You should be able to do:

Code: [Select]
prog_uchar *mess[] = {"Some long text phrase",
 "another long text phrase",
 "once upon a time",
 "to be or not to be" };


Yes, I've figured that out. The issue is that I would like to be able to easily edit the text phrases, but still refer to them by number. I'm perplexed that the compiler will let me make open-ended strings (arrays) - but then gags when I try to make them two dimensional. I guess I could set up an array of pointers, and a function to cycle through all my arrays to initialize the array of pointers.

It might clean up my other code a little.


Go Up