"pillbug" <_pillbug@socal.rr.com> wrote in message
news:Y7pNe.4787$UE2.1882@tornado.socal.rr.com...[color=blue]
> hswerdfe wrote:[color=green]
> > is there a standard function that formats data the same way that[/color][/color]
printf[color=blue][color=green]
> > and sprintf do.
> >
> > only the return value is a char*/string of the formated values.
> >[/color]
>
> #include <cstdarg>
> char* mysprintf (char* buf, const char* fmt, ...)
> {
> va_list va;
> va_start (va, fmt);
> vsprintf (buf, fmt, va);
> va_end (va);
> return buf;
> }[/color]
Here's a variation on this theme that doesn't need a buffer to be passed
in. It uses a small pool of statically allocated buffers. Using a pool
of buffers rather than a single buffer means that it can safely be used
several times in a single statement. Adjust NumLines and the buffer
size to suit your taste/needs.
char* Format (const char* fmt, ...)
{
const int NumLines = 5;
static int Line = 0;
static char Text[NumLines][200];
va_list args;
va_start (args, fmt);
vsprintf (Text[Line], fmt, args);
va_end (args);
int n = Line;
++Line;
if (Line >= NumLines)
{
Line = 0;
}
return Text[n];
}
--
Regards,
Joe Hotchkiss,
http://joe.hotchkiss.com http://harrowsubaqua.org.uk
XXXXXXXXXXXXXXXXXXXXXXXXX
X joe.hotchkiss X
X at selex-sas.com X
XXXXXXXXXXXXXXXXXXXXXXXXX