[Débutant]Fonction à arguments variables
Bonjour à tous;
J'essaie d'utiliser une fonction à arguments variables; mais quand je l'appelle avec un seul argument ça ne marche, et la méthode vsnprintf génère une exception, mais avec deux paramètre ça marche.
Auriez-vous une solution ou une explication, pourquoi j'ai une exception à ce niveau. Merci à tous.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
CString GetMessages(const char* arg,...)
{
CString LstMsg;
char buf[4096], *p = buf;
const char* format="%s";
va_list args;
va_start(args, arg);
p += _vsnprintf(p, sizeof buf - 1, format, args);
while ( p > buf && isspace(p[-1]) ) {
*--p = '\0';
}
*p = '\0';
char msg[4096];
sprintf (msg, format, buf);
LstMsg=msg;
return LstMsg;
} |