1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
typedef struct fonction{
char c;
int (*f) (void *);
} my_struct;
my_struct info[] =
{
{'d', option_d},
{'u', option_u},
{0,0}
};
int search(char *str, ...)
{
va_list ap;
char *f;
va_start(ap, str);
for (f = str; *f; f++)
{
if (*f == '%')
{
*++f;
// je bloque ici je ne sait pas lui dire si *f == 'd' alors il execute la fonction se situant dans option_d.c ect.................... je sait qu'il nous faut parcourir notre structure mais comment?
int k;
const my_struct * the_struct;
for (k = 0, the_struct = NULL; the_struct == NULL && info[k].c != 0; k++)
{
if (info[k].c == *f)
{
the_struct = info + k;
}
}
if (the_struct != NULL)
{
the_struct->f(NULL /* ton paramètre */);
}
}
else
my_putchar(*f);
}
va_end(ap);
}
} |
Partager