Pointer to an Array of Pointers(?)

How can one setup an array of arrays? With the example below I would like to try and do the following

I would think this would give me = 11

string_table[0][0]
string_table[0] ← being the pointer to the 1st (zero) array {arrayOne} and [0] being the 1st (zero) element in arrayOne.

string_table[0][0] == 21 (I would think)
string_table[0][1] == 22 (ok last example)

I’ve looked around and started (tried) to read up on pointers/etc but I’m in over my head with this I think.

Here’s a great read: http://home.earthlink.net/~momotuk/pointers.pdf

#include <avr/io.h>
#include <avr/pgmspace.h> 


  static unsigned char arrayOne[] PROGMEM = {
    11, 12, 13, 14, 15     };

  static unsigned char arrayTwo[] PROGMEM = {
    21, 22, 23, 24, 25     };

  PROGMEM static unsigned char *string_table[] = 	   // change "string_table" name to suit
  {   
    arrayOne,
    arrayTwo   };

void setup(){

    Serial.begin(9600);
    Serial.println("Starting...");
}

void loop(){
  
  char buffer[30];    // make sure this is large enough for the largest string it must hold

  for (int i = 0; i < 4; i++)
  {
   strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));
   // strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])[0]));
    Serial.print("Buffer: ");
    Serial.println(buffer);
    delay( 500 );
  }

}

Since you are mixing in PROGMEM, I would advise reading this: http://www.nongnu.org/avr-libc/user-manual/pgmspace.html

This discussion deals with multi-dimensional arrays, especially arrays of string pointers.

That doc seems to address: - mulitdemensional arrays in PROGMEM (good) - array of pointers to STRINGS (each defined on their own)

but it doesn't seem to cover an array of pointers to another array.

From that article it shows how to use pointers to string_table but it never shows how to retrieve a value from mydata[11][10] using a pointer from a table. I want to have something like mydata1, mydata2, etc and then a pointer to that table where I could call *myTablePointer[0][0] should give us the 1st value frfom the mydata1 table.

I can't figure out why this won't work ....I'm still stumped trying to figure this key piece out:

uint8_t line = pgm_read_word(table_pointers[fontnum]+(c*(myFontWidth*2))+i);

or in basic terms

char printValue = pgm_read_word(table_pointers[fontnum] + i);

I get back strange numbers that stay the same even if we i++

I've been reading another thread that starts to address but they didnt solve and went a diff approach

http://arduino.cc/forum/index.php/topic,43359.0.html

You’re trying to use strcpy_P to copy things that are not null-terminated strings. This works:

#include <avr/io.h>
#include <avr/pgmspace.h> 

static unsigned char arrayOne[] PROGMEM = {
    11, 12, 13, 14, 15     };

static unsigned char arrayTwo[] PROGMEM = {
    21, 22, 23, 24, 25     };

PROGMEM static unsigned char * PROGMEM string_table[] = 	   // change "string_table" name to suit
{   
    arrayOne,
    arrayTwo   
};

void setup()
{
    Serial.begin(9600);
    Serial.println("Starting...");
}

void loop()
{
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 5; ++j)
    {
       PROGMEM unsigned char* ptr = (PROGMEM unsigned char*)pgm_read_word(&string_table[i]);
       unsigned char val = pgm_read_byte(ptr + j);
       Serial.print("Value: ");
       Serial.println((int)val);
    }
    delay( 500 );
  }
}

Wow, I was way off. Thanks.

PROGMEM unsigned char* ptr = (PROGMEM unsigned char*)pgm_read_word(&string_table[i]);
unsigned char val = pgm_read_byte(ptr + j);

The way I read this is that the 1st line is getting the ‘i’ array from string_table and then we’re using a pointer to that + j to get the value. I’m not sure why we have all the PROGMEMs in there but I’ll take it at face value.

Kotoc: char printValue = pgm_read_word(table_pointers[fontnum] + i);

I don't see table_pointers[] mentioned in your example above, so let me guess what you have:

uint16_t table1[] PROGMEM = { 1, 2, 3, 4 };
    :
uint16_t table4[] PROGMEM = { 1, 2, 3, 4 };

uint16_t *table_pointers[] PROGMEM = { table1, table2, table3, table 4 };

If this is what you have, then the statement you mention will not work because you are reading from program memory only once, not twice as is needed. Something like this should be better:

char printValue = pgm_read_word(pgm_read_word(table_pointers[fontnum]) + i);

since table_pointers[] is itself in progmem, you must use pgm_read_word to get the pointer value to the sub-table. Then compute your offset into the sub-table, and pgm_read_word that.