wrapper printf function that filters according to user preferences

前端 未结 3 836
死守一世寂寞
死守一世寂寞 2021-02-04 01:42

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

3条回答
  •  误落风尘
    2021-02-04 02:30

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

    #include 
    
    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.

提交回复
热议问题