How to write a wrapper for printf?

K

kj

I want to write a function foo that I can call with a variable list
of arguments, and so that all but the first n arguments are passed
by foo directly to printf. E.g., if n=3, calls to foo would look
like this:

foo( some, leading, args, "a format string with %d slot", 1 );

or

foo( also, suitable, params, "a %s with %d slots", "template", 2 );

and in these cases, foo at some point would execute calls to

printf( "a format string with %d slot", 1 );

and

printf( "a %s with %d slots", "template", 2 );

respectively.

Can someone show me (or point me to where I can learn) how to do
this?

TIA!

Kynn
 
G

Guest

I want to write a function foo that I can call with a variable list
of arguments, and so that all but the first n arguments are passed
by foo directly to printf.  E.g., if n=3, calls to foo would look
like this:

  foo( some, leading, args, "a format string with %d slot", 1 );

or

  foo( also, suitable, params, "a %s with %d slots", "template", 2 );

and in these cases, foo at some point would execute calls to

  printf( "a format string with %d slot", 1 );

and

  printf( "a %s with %d slots", "template", 2 );

respectively.

Can someone show me (or point me to where I can learn) how to do
this?

read the FAQ, Luke!

the comp.lang.c FAQ can be found at http://c-faq.com/index.html

FAQ 15.5
"How can I write a function that takes a format string and a
variable number of arguments, like printf, and passes them to
printf to do most of the work?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top