Re: function with ? parameters
From: Larry Brasfield (donotspam_larry_brasfield_at_hotmail.com)
Date: 11/08/04
- Next message: David L: "Re: function with ? parameters"
- Previous message: David L: "Re: function with ? parameters"
- In reply to: David L: "function with ? parameters"
- Next in thread: David L: "Re: function with ? parameters"
- Reply: David L: "Re: function with ? parameters"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 8 Nov 2004 00:08:20 -0800
"David L" <drummy@nowhere.fr> wrote in message news:418f1285$0$5365$626a14ce@news.free.fr...
> Hello,
Hi.
> how to implement a sprintf-like function with unknown number of parameters
> AND with unknown type of parameters?
Here are some code snippets that demonstrate use
of varadic parameters in a portable manner. Note
that it would be possible to combine the functions
shown into a single function, but having them
separated makes the usage of va_list clearer with
respect to setup, per-argument processing, and
cleanup.
#include <stdarg.h>
ushort
StrFormatV(char *buffer, ushort maxlen, const char *format, va_list args)
{
...
while (char fmtc = *format++) {
...
switch (fcode) {
case int_type:
{
long ivalue;
ivalue = (va_arg(args, long));
...
}
...
}
...
}
ushort
StrFormat(char *buffer, ushort maxlen, const char *format, ...)
{
va_list vlist;
va_start(vlist, format);
short rv = StrFormatV(buffer, maxlen, format, vlist);
va_end(vlist);
return rv;
}
> thanx
> David
-- --Larry Brasfield email: donotspam_larry_brasfield@hotmail.com Above views may belong only to me.
- Next message: David L: "Re: function with ? parameters"
- Previous message: David L: "Re: function with ? parameters"
- In reply to: David L: "function with ? parameters"
- Next in thread: David L: "Re: function with ? parameters"
- Reply: David L: "Re: function with ? parameters"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|