Pages: [1]   Go Down
Author Topic: 2 dimensional text arrays  (Read 969 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 267
dinosaur cork
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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:
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?

PB
« Last Edit: September 27, 2007, 12:21:17 pm by paulb » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6632
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
prog_uchar *mess[] = {"Some long text phrase",
  "another long text phrase",
  "once upon a time",
  "to be or not to be" };
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 267
dinosaur cork
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Paul
Logged

Pages: [1]   Go Up
Jump to: