You are not logged in.

#1 2011-10-24 06:28:02

tony5429
Member
Registered: 2006-03-28
Posts: 1,025
Website

[SOLVED] Passing Argument Pointers between Variadic C Functions

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 -1781179032

And 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

#2 2011-10-24 06:44:48

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED] Passing Argument Pointers between Variadic C Functions

Use vsprintf in place of sprintf.


This silver ladybug at line 28...

Offline

#3 2011-11-09 04:41:05

tony5429
Member
Registered: 2006-03-28
Posts: 1,025
Website

Re: [SOLVED] Passing Argument Pointers between Variadic C Functions

So simple! Thanks!

Offline

Board footer

Powered by FluxBB