By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,388 Members | 1,901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,388 IT Pros & Developers. It's quick & easy.

transfering variable length argument list

P: n/a
Is it possible to transfer a variable length argument
list? What I want to do is just

void myPrintf( char *pFormat, ... ) {
char buf[256];
sprintf( buf, pFormat, ... );
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ANDERS FLODERUS wrote in news:1p**************@nntpserver.swip.net:
Is it possible to transfer a variable length argument
list? What I want to do is just

void myPrintf( char *pFormat, ... ) {
char buf[256];
sprintf( buf, pFormat, ... );
.
.
.
return;
}

which obviously will not compile. If possible, I would
like to do it without using the va_... macros while stepping
throu the format specifier. I suppose it would be possible
althou I do not know what type the arguments are (could
be found in the format specifier?).


#include <cstdio>
#include <cstdarg>

void myPrintf( char const *pFormat, ... )
{
using namespace std;

char buf[256];

va_list va;
va_start( va, pFormat );

vsprintf( buf, pFormat, va );
/* _vsnprintf is non standard but your compiler may provide it.
If so its *safer* than the above.
*/
//_vsnprintf( buf, sizeof buf, pFormat, va );
va_end( va );

printf( "buf = [%s]\n", buf );
}

int main()
{
myPrintf("test %d", 1 );
}

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.