Hi. I'm attempting to make a variable arguement function using the functions and
tools provided in <stdarg.h> .. Upon reading the man page stdarg (under Linux),
I was able to put together a small function based on their foo() example.
Unfortunately, the switch statement does not work. I can pass "strings",'c',1 ..
to the function and nothing will be printed. I had attempted to get around that
by removing the switch (since I plan to only pass strings). However, a version
such as this would print a blank line followed by unallocated memory:
void food(char *fmt, ...){
va_list ap;
char *s,buf[BUFSIZ+1];
va_start(ap, fmt);
while (*fmt++){
s = va_arg(ap, char *);
printf("%s\n",s);
}
va_end(ap);
In some cases, that example would even seg fault after printing theQuote:}
line of strings I sent it. Another note, it would not print the first string
either.