Solved

example for a variable parameter list function?

Posted on 2001-06-19
4
177 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 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now