sprintf function
by Bryan "daerid" Ross · in Torque Game Engine · 12/03/2001 (12:14 pm) · 2 replies
Anybody have a ready made sprintf function for the TGE?
What I'm thinking of is the Tribes 1 sprintf function.
To show you what I mean:
sprintf( "The %1 jumped over the %2 %3", "fox", "lazy", "dog" );
What I'm thinking of is the Tribes 1 sprintf function.
To show you what I mean:
sprintf( "The %1 jumped over the %2 %3", "fox", "lazy", "dog" );
#2
Coded it meself:
12/03/2001 (5:49 pm)
n/mCoded it meself:
ConsoleFunction(sprintf,const char *,1,10,"sprintf(string,arg1,arg2...arg9);")
{
argc;
char * ret = Con::getReturnBuffer(1024);
ret[0] = '[[60c216ed3c392]]'; //initialize and terminate the string
char chr[2];
const char *ptr = argv[1];
while( *ptr != '[[60c216ed3c392]]' )
{
if( *ptr == '%' )
{
if ( ptr[1] >= '1' && ptr[1] <= '9' )
{
chr[0] = ptr[1];
if ( ( dAtoi(chr) + 1 ) < argc )
{
dStrcat( ret, argv[ dAtoi(chr)+1 ] );
ptr+=2; // skip the %n
continue;
}
}
}
chr[0] = *ptr;
chr[1] = '[[60c216ed3c392]]';
dStrcat( ret, chr );
ptr++;
}
return ret;
}
Associate Justin Mette
Default Studio Name
"The " @ %animal @ " jumped over the " @ %thing1 @ " " @ %thing2 @ "."