#include <iostream>
#include <stdarg.h>
enum {OOC,CHAT,INFO,DEBUG};
void print(int type,char *txt,...)
{
va_list args;
va_start(args,txt);
printf(txt,args);
va_end(args);
}
int main()
{
int n=-50;
print(DEBUG,"%i",n);
return 0;
}
It does nothing now, but later sprintf will be used to decide where to put it based on the type. My problem is that it returns -1073742616. It returns the same value every time, even after code changes and recompiles. When I change it to printf and remove the DEBUG arguement, it gives -50 as expected. Am I passing the arguement list wrong?
passing va_list
I am trying to write a function that takes variable parameters like printf and attempts to pass them on to printf. The function right now just passes the va_list on to printf. Here is my code:
Use vprintf, not printf.
vprintf( txt, args );
Similarly, use vsprintf for putting it in a string:
vsprintf( str, txt, args );
~CGameProgrammer( );
-- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..
vprintf( txt, args );
Similarly, use vsprintf for putting it in a string:
vsprintf( str, txt, args );
~CGameProgrammer( );
-- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement