You are not logged in.
So I'm trying to create a variadic function in C/C++ to send a printf-type-formatted-string to the shell via the system command. This is what I've got in my .h file,
#include <stdarg.h>
inline void sysprintf(const char *fmt, ...) {
char str[2000];
memset(str, 0, 2000);
va_list argptr;
va_start(argptr, fmt);
sprintf(str, fmt, argptr);
system(str);
va_end(argptr);
}However, when I call the function with sysprintf("echo hello world %i", 5); I actually get this,
hello world -1781179032And that number seems to be random. Does anyone know what's going on and how I can fix it? Thanks!
Last edited by tony5429 (2011-11-09 04:41:21)
Offline
Use vsprintf in place of sprintf.
This silver ladybug at line 28...
Offline
So simple! Thanks!
Offline