renanlopesmister:
Well, I need to redo all my print routines so that these routines, instead of receiving an array of RAM characters as a parameter, get a byte-byte reading of the strings in flash memory, for example, and print as desired. This will be quite laborious, but my scketch is not working anyway ...
Why byte-by-byte? It's still not clear to me what you want to achieve. For simple concatenation of two strings that are stored in flash, see reply #7.
In the below, I used strcpy_P (I forgot about strcat) which will give the same result; the strings are stored in flash but the pointer array is however stored in ram.
const char hello[] PROGMEM = "Hello";
const char space[] PROGMEM = " ";
const char world[] PROGMEM = "world";
const char *texts[] =
{
hello,
space,
world,
};
void foo(char *b, const char *t[], int numElements)
{
for (int cnt = 0; cnt < numElements; cnt++)
{
strcpy_P(&b[strlen(b)], t[cnt]);
}
}
void setup()
{
Serial.begin(57600);
char buffer[64];
buffer[0] = '\0';
strcpy_P(buffer, texts[0]);
Serial.print("'"); Serial.print(buffer); Serial.println("'");
strcpy_P(&buffer[strlen(buffer)], texts[1]);
Serial.print("'"); Serial.print(buffer); Serial.println("'");
strcpy_P(&buffer[strlen(buffer)], texts[2]);
Serial.print("'"); Serial.print(buffer); Serial.println("'");
buffer[0] = '\0';
foo(buffer, texts, sizeof(texts) / sizeof(texts[0]));
Serial.print("'"); Serial.print(buffer); Serial.println("'");
}
void loop()
{
}
renanlopesmister:
But why can I pass the strings, which are in flash memory, to a buffer one way and not another?
Do you mean, why can I read but not write?