Solved

example for a variable parameter list function?

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

860 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