On Fri, 12 May 2000, Alex generated:
> Wayne wrote:
>> void log_msg(char *fmt, ...)
>> {
>> FILE *fd = fopen("/tmp/mylog", "a");
>> va_list arglist;
>>
>> va_start(arglist, fmt);
>> vfprintf(fd, fmt, arglist);
>> fclose(fd);
>> }
>I'm not familiar with vs_list and va_start (though I can guess that
>vfprintf() is probably a variant of fprintf()), could you give a brief
>explanation?
I semi-understand it -- enough to know what it does but I couldn't
implement it without lots of thinking :)
Basically, you can specify a variable number of arguments to functions,
the compiler does some magic and this comes as a pointer to an array of
char *'s. Any function that does this must know how many arguments to
process, this is where the format string in *printf come in, it parses
the string for % characters and replaces them with the contents of the
next argument in the list. Needless to say, the type of the argument
must match the type given in the format string.
I'm sure others can put that better ;)
>> The you can do things like
>>
>> log_msg("SQL is : ", sqlstr);
log_msg("SQL is: %s", sqlstr);
^
You need the % placeholders in the format string ;)
--
jamesw
<Hoju> Keyboard solo! skskskskskskskskskskskskskskskskskskskskksksksksks
------------------------------
[EMAIL PROTECTED]
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text