FW: need C++ help (for code that will become part of GME)

GME GME
Wed Nov 19 20:59:57 CST 2003



----------
From: 	Brian Williams
Sent: 	Wednesday, November 19, 2003 2:59:57 PM
To: 	GME Group
Subject: 	RE: need C++ help (for code that will become part of GME)
Auto forwarded by a Rule

Thanks Jon,

 

I shoulda made the subject say “code that _may_ become part of GME”, because of course, I have to make it work first.

 

I have already made a function that just takes strings, and dumps them to a file (GME Event Logging), but I’d like to make it as smart as printf, so instead adding several lines of code everywhere an interesting event occurs, I can just add one.

 

Brian

 

-----Original Message-----
From: GME Group 
Sent: Wednesday, November 19, 2003 2:52 PM
To: GME List
Subject: FW: need C++ help (for code that will become part of GME)

 

 


----------

From:   Jonathan S. 
Sent:        Wednesday, November 19, 2003 2:52:15 PM 
To:      GME Group 
Subject:       RE: need C++ help (for code that will become part of GME) 
Auto forwarded by a Rule

 

Whooooa, stallion.  Here's the code snippet, but you should be wanred that in general, passing a variable number of arguments is hackworthy, especially when theya re void's.

 

The trick is to use "v{f,s, }printf" instead of {f,s, }printf, and pass the poitner to the arglist (v1 below). You can tell taht someone has wanted to do this before.  :)

 

good luck,

Jon

 

#include <cstdio>
#include <iostream>
#include <string>
#include <stdarg.h>
using namespace std;

 

string MyPrintf( char * sz, ... );

 

void main( void )
{
 cout << MyPrintf( "My name is %s %s %s", "Jonathan", "Mark", "Sprinkle" ) << endl;
}

 

string MyPrintf( char * sz, ... )
{
 string result;
 char jon[2222]="";

 

 va_list v1;
 va_start( v1, sz );
 vsprintf( jon, sz, v1 );
 va_end( v1 );
 result = string( jon );
 return result;
}




More information about the gme-users mailing list