Original Post
How would I go about making a variable argument function? Here's is my bitmap font engine for my SDL games (the proplem doesn't really have to do directly with the SDL API), and I want to be able to to take a variable amount of arguments, clump them to one string (like I could with sprinf)then apply the text. how do I work with a variable arguments? my problems are the lines commented /* like this */ I would like to learn a cross platform method of doing this.
///////////////////////////////////////////////////////////////////////////////////
void LFont::text_out( int x, int y, SDL_Surface *thisSurface, char *myString, ... )
///////////////////////////////////////////////////////////////////////////////////
{
//string buffer
string buf;
/* get the arguments */
//get the new x and y coordinates
this->y = y;
this->x = x;
//go thorugh the string
for( int copy = 0; myString[ copy ] != '\0'; copy++ )
{
if( myString[ copy ] == '%' )
{
copy++;
switch( myString[ copy ] )
{
case '%':
buf += '%';
break;
case 'i':
/* get the next argument as an integer */
/* append it to the string */
break;
case 's':
/* get the next argument as a C string ( char * ) */
/* append it to the string */
break;
case 'S':
/* get the next argument as a string object */
/* append it to the string */
break;
}
}
else
{
buf += myString[ copy ];
}
}
//apply the string to the surface
apply_text( buf.c_str(), thisSurface );
}