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

  • SEARCH
  • Home
  • 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 393159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:13:48+00:00 2026-05-12T16:13:48+00:00

My program writes to a log and to stdout. Every message, however, has a

  • 0

My program writes to a log and to stdout. Every message, however, has a certain priority and the user specifies in Preferences which priorities go to which stream (log or stdout).

unsigned short PRIO_HIGH = 0x0001;
unsigned short PRIO_NORMAL = 0x0002;
unsigned short PRIO_LOW = 0x0004;

The preferences is handled by some flags:

unsigned short PRIO_LOG = (PRIO_HIGH | PRIO_NORMAL);
unsigned short PRIO_STD = (PRIO_HIGH);

The write_log function should work with the same parameters as the printf function, with the added parameter of unsigned short priority.

write_log((PRIO_NORMAL|PRIO_LOW), "HELLO %s, take %d", "World", 1);

(Even if PRIO_NORMAL|PRIO_LOW makes little sense…)

Checking the flags is easy: if(priority & PRIO_LOG) (Returns >1 if any flag is set in both arguments)

I cannot however find out how I would go about passing the string literal and the format arguments to the printf function. Can anyone help or give me a pointer (possible to an alternative method that achieves the same effect)? It would be much appreciated.

  • 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-05-12T16:13:49+00:00Added an answer on May 12, 2026 at 4:13 pm

    You want to call vprintf() instead of printf() using the variable arguments “varargs” capabilities of C.

    #include <stdarg.h>
    
    int write_log(int priority, const char *format, ...)
    {
        va_list args;
        va_start(args, format);
    
        if(priority & PRIO_LOG)
                vprintf(format, args);
    
        va_end(args);
    }
    

    For more information, see something along the lines of this.

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

Sidebar

Ask A Question

Stats

  • Questions 209k
  • Answers 209k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can specialise the method for that type. E.g. template<typename… May 12, 2026 at 9:42 pm
  • Editorial Team
    Editorial Team added an answer We have decided you go the stored procedure route for… May 12, 2026 at 9:42 pm
  • Editorial Team
    Editorial Team added an answer Use ConfigurationManager.ConnectionStrings collection to access the connection stings that stored… May 12, 2026 at 9:42 pm

Related Questions

I work a lot with network and serial communications software, so it is often
I am working with VMD (a molecular dynamics visualization package) and I want to
I think I'm failing to understand some finer point of C++. I want to
Is it possible to open a file in .NET with non exclusive write access?
I have a VB app that I need to monitor while it is running.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.