[lug] variable length parameters

Holshouser, David dholshou at ball.com
Thu May 3 14:43:19 MDT 2001


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  




More information about the LUG mailing list