In my code I can pass one element of a pointertable to char arrays but not all. Any idea.
#include <avr/pgmspace.h>
const char string_0[] PROGMEM = "String 0"; // "String 0" etc are strings to store - change to suit.
const char string_1[] PROGMEM = "String 1";
const char string_2[] PROGMEM = "String 2";
const char string_3[] PROGMEM = "String 3";
const char string_4[] PROGMEM = "String 4";
const char string_5[] PROGMEM = "String 5";
// Then set up a table to refer to your strings.
const char* const string_table[] PROGMEM = {string_0, string_1, string_2, string_3, string_4, string_5};
char buffer[300]; // make sure this is large enough for the largest string it must hold
int ii;
void setup()
{
Serial.begin(115200);
while(!Serial);
}
void loop()
{
Serial.println("Buffered:");
for (int i = 0; i < 6; i++)
{
if (i==0) { //1ste x !! cpy
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));
} else {// verder cat
strcat(buffer," -*- ");
strcat_P(buffer, (char*)pgm_read_word(&(string_table[i])));
}
}
Serial.println(buffer);
Serial.print("not buffered (2 ways) : 1 element 0 first way:");
Serial.println ((const __FlashStringHelper *) string_table[0]);// Printen van FlashMEM!!
Serial.print("not buffered: second way:");pF(string_table[0]);
Serial.println("not buffered all of them:");
for (ii=0;ii<6;ii++)
{
pF(string_table[ii]);
}
Serial.println("-------------");
delay(25000);
}
void pF(char * p){
//Serial.print("buffer is=");Serial.println(buffer);
//Serial.print("p is=");
Serial.println((const __FlashStringHelper *)p);
}
my output is not ok (garbage) when using 'pF(string_table[ii])' instead of 'pF(string_table[0])':
Buffered:
String 0 -*- String 1 -*- String 2 -*- String 3 -*- String 4 -*- String 5
not buffered (2 ways) : 1 element 0 first way:String 0
not buffered: second way:String 0
not buffered all
⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
Someone can help?