[lug] variable length parameters

Chip Atkinson catkinson at circadence.com
Thu May 3 14:51:16 MDT 2001


Check out vprintf.  That's the function you want to use.

Holshouser, David wrote:

> This is a pure c programming question, if there is a better place to ask it,
> I don't know about it.
> 
> I'm trying to build a few functions for error and status logging.
> What I want to do is take a variable length parameter list, act according to
> which function was called, and then pass the stuff on to printf or maybe my
> own bastardised printf.
> 
> Question:
> can I have a function that takes variable parameters and pass those
> parameters on [with/out modification] to another function that takes
> variable parameters.
> 
> my simple test:
> =========================================================
> #include<stdio.h>
> #include<stdarg.h>
> 
> void test(char *fmt, ...)
> {
>     va_list ap;
>     va_start(ap, fmt);
>     printf(fmt, ap);
>     va_end(ap);
> }
> 
> int main (void)
> {
>     int i=1;
> 
>     test("foo%dbar\n", i);
> }
> =========================================================
> 
> my simple test bombs with:
> foo37813904bar
> as output.
> 
> Any ideas on how to accomplish this?
> 
> 
> --
> David Holshouser
> Engineer I
> Ball Aerospace & Technologies Corp.
> (303)939-5085  dholshou at ball.com  
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug




More information about the LUG mailing list