In a function like printf, we use stdarg.hto process variable parameters.
void print(int args,...){
va_list ap;
va_start(ap, args);
int i = 0;
for(i=0; i<args; i++){
printf("%d\n",va_arg(ap, int));
}
va_end(ap);
}
We want to parse the list of formats (the first argument provided to our variational function) to track the types of arguments specified in the list of formats, then call va_arg with the appropriate type.
I am doing the first loop to parse the list of formats, storing the letters of the qualifiers in an array. So I know what type we expect and how much there.
ex: ft_like_printf("Watch your %d %s\n", 6, "Spider pig");
specifiers_list = "ds"
So d <=> int and s <=> char * (same qualifiers as printf)
But how to encode it dynamically ? What is the syntax for calling va_arg with different types?
THAT, , , , , ?
, ? , enum + union struct, union + function?
, :
typedef struct s_flist
{
char c;
(*f)();
} t_flist;
t_flist flist[] =
{
{ 's', &putstr },
{ 'i', &put_number },
{ 'd', &put_number }
};