#include <stdarg.h>
char *P(char *fmt, ... ){
static char tmp[128]; // resulting string limited to 128 chars
Serial.println("A");
va_list args;
Serial.println("B");
va_start (args, fmt );
Serial.println("C");
vsnprintf(tmp, 128, fmt, args);
Serial.println("D");
va_end (args);
Serial.println("E");
delay(100);
return tmp;
}
void setup()
{
Serial.begin(9600);
Serial.println("Starting...");
}
void loop()
{
String XMLTagStrings[] = {
"data",
"temperature",
"humidity",
"dateTime"
};
Serial.println("Before Call");
delay(100);
char *data = P("%s", "Chris");
//char *data = P("%s", XMLTagStrings[1]);
Serial.println("After Call");
Serial.println(data);
delay(1000);
}
This example shows the issue.
As is it will run but comment out the
char *data = P("%s", "Chris");
and uncomment the
//char *data = P("%s", XMLTagStrings[1]);
and you will see it never prints "A" inside the P function where it does with the previous call with a static string "Chris"
Hope this helps someone help me.
Chris