Archived

This topic is now archived and is closed to further replies.

billybob

va_list and ...

Recommended Posts

i''m trying to simply get a ... from my function to fprintf. i''ve never used this before, and the only example i found on the internet required you to pass the number of args (it was an average function). all i really need is how to get this to work:
void blahblah(char * FormatString, ...)
{
   fprintf(FormatString, ???);
}
 
what do i put in the ???

Share this post


Link to post
Share on other sites
C-FAQ question 15.12:
How can I write a function which takes a variable number of arguments and passes them to some other function (which takes a variable number of arguments)?

In short: You can't.

If you really want to do it, you could do it like this:

#include <stdio.h>
#include <stdarg.h>

void blahblah(char *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
vfprintf(stdout, fmt, argp); //instead of stdout, you could use a *FILE.
va_end(argp);
}


[edited by - TravisWells on March 16, 2003 11:51:39 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by billybob
oops, i meant to have a FILE *, i just typed that real quick, i think thats it anyway. all i need to do is get the ... from my function to fprintf''s


Which is what vfprintf() does. The first parameter is FILE *



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites