?
Solved

example for a variable parameter list function?

Posted on 2001-06-19
4
Medium Priority
?
192 Views
Last Modified: 2010-04-15
basically I'd like to re-direct the fprintf function..
to allow me a little more control of error messages.

the idea is simple, write a new function

flogf( "a format string - %s %d %c \n", var1, var2,... );

then define flogf to pass these variables through and write to either stderr, to a file, or both depending on the configuration...

Does anyone have an example to illustrate how this is done?

thx, George
0
Comment
Question by:gljr
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6207525
Sure, just use a function similar to this one:

#define LOG_REPORT_BUFSIZE      2048    //  way too big, but as anything
                                       //  may be passed in...

void    __cdecl DbgPrintf       (   char*   __pszFormat,    ...)
{
   static  char    s_acOutput      [   LOG_REPORT_BUFSIZE  +   MAX_PATH];
   static  char    s_acBuf         [   LOG_REPORT_BUFSIZE];

   va_list         args;

   va_start    (   args,   __pszFormat);

   vsprintf   (   s_acBuf,    __pszFormat,    args);

   sprintf    (   s_acOutput,
                   "%s%s",
                   s_acBuf,
                   strchr  (   s_acBuf,    '\n')   ?   "\0"    :   "\r\n"
               );

   // wite 's_acOutput' to file, stderr, or to what you want :o)

   va_end  (   args);
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 6212483
Is there anything else you'd like to know?
0
 

Author Comment

by:gljr
ID: 6224881
Thanks jkr,

Actually, I found a similar example about the same time
you published this one.. and I don't think it will be efficient to use this right now.. but I really do apreciate your promtness :-)

George
0
 

Author Comment

by:gljr
ID: 6224882
Thanks jkr,

Actually, I found a similar example about the same time
you published this one.. and I don't think it will be efficient to use this right now.. but I really do appreciate your promtness :-)

George
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question