I want to develop a basic function which includes the printf() one. Having troubles with the arguments of the function
I'm trying to develop a basic function similar to this one:
basi_fun(const char* CMD, val1, val2, val3)
{
     fun1();
     printf(CMD,val1,val2?,...);
     fun2();
}
The problem is related to the fact that I don't know how printf() is able to understand the number and type of variable needed. In a similar way I don't know how to allow my basic_fun() to ask for a variable number and type of parameter. 
By looking in the stdio.h header I understood that the function printf() is based on vfprintf(...):
extern int  vfprintf(FILE *__stream, const char *__fmt, va_list __ap);
and by means of __ap is able to accept a variable number of variables which number and types is defined by the number and type of %d,%c,etc inside the __fmt char array.
After this I tried to develop something similar to this:
basi_fun(const char *__fmt, va_list __ap)
{
     fun1();
     printf(__fmt, __ap);
     fun2();
}
Actually it still do not work. What am I missing? Also an indication on where to learn the __ap could be useful.
 
    