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
| #include <stdio.h>
#include <string.h>
#define FONC(X) { #X , X }
void doTest (void)
{
printf ("Fonction de test invoquée.\n");
}
void MaPremiereFonction (void)
{
printf ("Première fonction invoquée.\n");
}
void MaSecondeFonction (void)
{
printf ("Seconde fonction invoquée.\n");
}
int main (int argc,char ** argv)
{
unsigned int i;
struct {
const char * nom;
void (*ptr)(void);
} tab [] =
{
FONC(doTest),
FONC(MaPremiereFonction),
FONC(MaSecondeFonction)
};
if (argc>1)
for (i=0;i<(sizeof tab / sizeof *tab);++i)
if (!strcmp(argv[1],tab[i].nom))
(tab[i].ptr)();
return 0;
} |
Partager