title: wrapper for a function with variable arguments in C
body: <p>Recently I wanted to implement a <code>printf</code> wrapper. After some search I found the <code>vprintf</code> is good for this need:</p>
  
  <pre><code>void my_printf(const char *fmt, ...)
  {
      va_list args;
      va_start(args, fmt);
      vprintf(fmt, args);
      va_end(args);
  }
  </code></pre>
  
  <p>But is it possible to implement such a wrapper for <code>printf</code> or any other similar functions with variable arguments instead of <code>va_list</code>?</p>
  
  <p>(I mean, what if they don't provide a <code>v</code> version?)</p>
  
  <hr>
  
  <p>Since some commenter didn't fully capture my idea, I'd better elaborate it. </p>
  
  <p>Suppose you have a plain <code>printf</code> function as in the C library.</p>
  
  <p>Some one gives you a <code>fmt</code> string <code>"%d %u %f"</code>, and corresponding inputs.</p>
  
  <p>Now you want to write a function similar to <code>printf</code>, but with all <code>%f</code> replaced by <code>%.2f</code>.</p>
  
  <p>Of course you can use two statements to finish the task:</p>
  
  <pre><code>replace(fmt, "%f", "%.2f");
  printf(fmt, inputs);
  </code></pre>
  
  <p>But if you use this function many times, probably you want to have a wrapper to save some time. </p>
  
  <p>A macro can finish this task, of course. But is it possible without a macro, like:</p>
  
  <pre><code>void myprintf(fmt, ...)
  {
      replace(fmt, "%f", "%.2f");
      printf(fmt, inputs);
  }
  </code></pre>
  
  <p>The problem here is that you don't know how to feed the inner <code>printf</code> with the arguments <code>...</code> of <code>myprintf</code>.</p>
  
  <p>Hope this clarifies.</p>