Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:35:02+00:00 2026-06-13T04:35:02+00:00

Recently I wanted to implement a printf wrapper. After some search I found the

  • 0

Recently I wanted to implement a printf wrapper. After some search I found the vprintf is good for this need:

void my_printf(const char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    va_end(args);
}

But is it possible to implement such a wrapper for printf or any other similar functions with variable arguments instead of va_list?

(I mean, what if they don’t provide a v version?)


Since some commenter didn’t fully capture my idea, I’d better elaborate it.

Suppose you have a plain printf function as in the C library.

Some one gives you a fmt string "%d %u %f", and corresponding inputs.

Now you want to write a function similar to printf, but with all %f replaced by %.2f.

Of course you can use two statements to finish the task:

replace(fmt, "%f", "%.2f");
printf(fmt, inputs);

But if you use this function many times, probably you want to have a wrapper to save some time.

A macro can finish this task, of course. But is it possible without a macro, like:

void myprintf(fmt, ...)
{
    replace(fmt, "%f", "%.2f");
    printf(fmt, inputs);
}

The problem here is that you don’t know how to feed the inner printf with the arguments ... of myprintf.

Hope this clarifies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:35:03+00:00Added an answer on June 13, 2026 at 4:35 am

    If you just want to use this to prepend an string to the output or so, you could use a variadic macro.

    #define MYPRINT(...) printf("toto has: " __VA_ARGS__)
    

    in that simple example this suppposes that format that you pass in is a string literal, so this is a bit restricted. But I hope you see the pattern how to use such simple macro wrappers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read about Single-Page Applications recently and wanted to try one out. After watching
I wanted to list all my Recently Used Items. I use this code: public
I recently downloaded Visual Studio 2010b2, and wanted to re-evaluate some of my questions
This is something that's I've wanted to know recently, mostly out of curiousity. I'm
I recently wanted/thought I need a form with two child forms to switch between
So I recently wanted to use the jQuery to do some browser detection and
I am creating a game. I have some UI with text. Recently we wanted
I recently wanted use regex in Cocoa app. But I found that Cocoa does
I recently wanted to build my own client-server system by using BSD sockets. After
Recently I wanted to try some of the new features in Scala 2.9 in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.