Solved

example for a variable parameter list function?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 175
How to creat good software interface ? 1 60
How to access ANSI/IEEE Std 754 or equivalent information ? 3 46
Computer slow / BSOD 10 44
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

861 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

23 Experts available now in Live!

Get 1:1 Help Now