Server Help

Non-Subspace Related Coding - C: Passing an unknown number of parameters and pass them on

Samapico - Wed Jan 21, 2009 12:52 pm
Post subject: C: Passing an unknown number of parameters and pass them on
I'm talking about some printf() style thing... Actually, I just want a function that receives some stuff, including a formatted string that will do some stuff, then do an actual printf with the parameters. So I don't even need to use those parameters, I'd just need to pass them back to the printf...

How would I do that?

I saw the printf header is declared like
Code: Show/Hide
printf(const char *, ...);

I'm guessing I can do that to my functions too, but in the definition of the function, how do I 'receive' those ... and how could I throw them back in the printf?


No big deal if it's not possible, and if the solution involves like 100 lines of code, forget it tongue.gif

This is C, not C++ too.
Dr Brain - Wed Jan 21, 2009 1:29 pm
Post subject:
Found this on google for variable arguments: http://www.cprogramming.com/tutorial/lesson17.html

Looks pretty simple, though I've not personally used it.
Samapico - Wed Jan 21, 2009 2:52 pm
Post subject:
Thanks... that helped; though I found the solution to my particular problem elsewhere

Code: Show/Hide

int my_printf(char* fmt, ...)
{
   int r;
   va_list args;
   va_start(args, fmt);
   r = vprintf(fmt, args);
   va_end(args);

   return r;

}

Quan Chi2 - Sat Jan 24, 2009 3:11 am
Post subject:
Dr Brain wrote:
Found this on google for variable arguments: http://www.cprogramming.com/tutorial/lesson17.html

Looks pretty simple, though I've not personally used it.


Ah... You beat me to it, Brain. tongue.gif I was reading that in school with a friend.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group