I'm getting confused on pointer and arrays and hopefully someone may shine some light.
I have the following arrays:
const prog_char array1[] PROGMEM ={0x00,0x01};
const prog_char array2[] PROGMEM ={0x00,0x01};
My function uses the array:
void test(const prog_char *iptr)
{
//Do something with iptr
}
Everything is well until here. I can call test(array1); and everything works as expected.
Now, I'd like to have an array like this:
const prog_char *myarray[] PROGMEM= {array1,array2};
How do I need to call my test() function and pass myarray[0] as argument?
Thanks in advance!!!
RI
To call the function is no different.
As myarray is an array of pointers, passing 'myarray[ 0 ]' is the same as 'array1', or:
test( myarray[0] );
test( *myarray ); //This is fine and is equivalent to accessing the first element.
The pointer myarray[0] resides in PROGMEM, not in SRAM. So you need to read itpgm_read_byte(myarray). Then you can use the value you just read and pgm_read_byte to get the values.
Good catch, I didn't see the PROGMEM on 'myarray',
To modify the function so you can do the pgm_read_byte inside the function, change it to:
void test(const char **iptr)
{
const char *arr1 = ( char* ) pgm_read_word( iptr );
const char *arr2 = ( char* ) pgm_read_word( iptr + 1 );
}
EDIT: changed byte to word for pointer size.
You don't need to use prog_char when passing the type. PROGMEM is an attribute, not a modifier like 'static', or 'const' and isn't remembered.
Yes right! Reading address is word and reading the actual char array element is byte. XD
Awesome!!!
Got it working now 
Thanks a lot!!!
No problem. If your data is a few arrays but all with the same length, then it's easier to chain them into one array in PROGMEM so you don't have to use pgm_read_xxx twice.