Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

example for a variable parameter list function?

Posted on 2001-06-19
4
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.
Suggested Courses

618 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