Hey there, hope you're having an awesome weekend! 
So............... yeah, my brain hurts. 
I have two functions that work with va_lists: one ("Say") that uses vsnprintf. It works in isolation. There other ("Write") calls Say and also the ncurses function "vw_printw" 9like a printf except that it also takes a va_list and works in the "ncurses" library). The ncurses part, obviously, also works in isolation. But when I try to put them both in the same function, "weird happens." For some reason, instead of putting the data (a const char * in my tests) into the string, it inserts the text "^P". I'm guessing the problem is the fact that I don't really know how va_lists work under the hood. There's probably some pointer moving somewhere, or something that got NULLed somehow... lol idk...
Anyway, here's the code:
Code:
void Say(bool rightNow, const char *format, ...) {
/* Declare variables */
va_list args;
char buffer[256];
/* Pass the variable arguments into our buffer */
va_start(args, format);
vsnprintf(buffer, 256, format, args);
printw("Saying: \"%s\n\"", buffer);
va_end (args);
/* Stop speech if theuser wants this text spoken immediately */
if (rightNow) espeak_Cancel();
/* Tell eSpeak to speak our buffer */
espeak_Synth((const char *)buffer, strlen(buffer) + 1, 0, POS_SENTENCE, 0, espeakCHARS_AUTO, NULL, NULL);
}
void Write(bool speakImmediately, const char * format, ...) {
va_list list1, list2;
va_start(list1, format);
vw_printw(stdscr, format, list1);
va_end(list1);
// Tried a second va_list... no dice
va_start(list2, format);
Say(speakImmediately, (char *)format, list2);
va_end(list2);
}
// Then the code that calls it, "Say" by itself seems to work.
Say(false, (char *)"What the %s?", "puck");
// Obviously, printw by itself works as well.
// But with this, I get "What the ^P?"
Write(false, "What the %s?", "puck");
At this point I'm considering abandoning my write function completely and just always calling speak and printw, which is kind of a setback (I'll have to add a lot more variables so I can pass them in to both functions etc.) but I can't find anything on the interwebz that would provide a logical explanation. Maybe passing a va_list to a function that uses a va_list is invalid somehow? Anyway I'm compiling this with GCC on 64-bit Linux Mint, using -Wall, and I'm not getting any warnings.
Thanks in advance.