Using PROGMEM with sprintf_P

I would like to use sprintf_P with both format string and arguments stored in PROGMEM.

char header_1[] PROGMEM = "Dissolved O2";
char buffer[100];
void setup() {
   Serial.begin(57600);
   sprintf_P(buffer,PSTR( "The column header is %s") ,(char*)pgm_read_word(header_1));
   Serial.println(buffer);
}
void loop(){}

Can this be done? I know I could use strcpy_P to move header_1 to an intermediate non-PROGMEM array but is there a better way?

char header_1[] PROGMEM = "Dissolved O2";
char buffer[100];
char buffer2[100];
void setup() {
   Serial.begin(57600);
   strcpy_P(buffer2,header_1);
   sprintf_P(buffer,PSTR( "The column header is %s") ,buffer2);
   Serial.println(buffer);
}
void loop(){}

Use %S instead of %s.

const char header_1[] PROGMEM = "Dissolved O2";

sprintf_P(buffer, PSTR("The column header is %S"), header_1);

Thanks!

I see that %S (capital S) is specific to avr C

S Similar to the s format, except the pointer is expected to point to a program-memory (ROM) string instead of a RAM string.

Is there a resource which highlights some of these avr specific additions?

RyanN: Thanks!

I see that %S (capital S) is specific to avr C

Is there a resource which highlights some of these avr specific additions?

Wow...I had no idea that the avr library used %S for flash strings. And a respectable amount of googling still doesn't find any simple list of them.

The best I could find was the description of vfprintf() here -> http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html

For the benefit of anyone who comes looking for this, here’s the correct syntax:

char header_1[] PROGMEM = "Dissolved O2";
char buffer[100];

void setup() {
   Serial.begin(57600);
   sprintf_P(buffer,PSTR( "The column header is %S") ,header_1);
   Serial.println(buffer);
}
void loop(){}

Note that the %S has a capital S because header_1 is in PROGMEM.

Thanks again to oqibidipo