progmem and sprintf


ok, doesn't work.  how cast or manipulate message does?  can see commented out line can put message in buffer strcpy_p.  works great.  can't figure out sprintf_p. 

code: [select]

void setup(){
 
  serial.begin(9600);
  serial.println("the serial works");
 
  printoutmessage(f("all base belong us!"));
 
}


void loop(){}

void printoutmessage(const __flashstringhelper* message){
 
  char buffer[40];
 
  //strcpy_p(buffer , (const prog_char*) message);
 
  sprintf_p(buffer, pstr("ha ha %s") , message);
 
  serial.println(buffer);
 
}



by way, know print overloaded this.  serial.print line there demonstration.  need able fill char buffer sprintf. 

tried too, doesn't work.  ends printing garbage on screen.  don't know it's trying read from.  progmem stuff has been spooky business me. 

code: [select]
sprintf_p(buffer, pstr("ha ha %s") , (char*) pgm_read_word (&message));


Arduino Forum > Using Arduino > Programming Questions > progmem and sprintf


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code