Voilà, j'ai dû par la force des choses me remettre au C, et comme mon programme (en CLI) a besoin d'arguments, je me suis dit que j'allais faire les choses bien et passer par la fonction
getopt_long qui fait justement ça
Pour commencer, j'ai naturellement pris l'exemple fourni
while (1)
{
static struct option long_options[] =
{
/* These options set a flag. */
{"verbose", no_argument, &verbose_flag, 1},
{"brief", no_argument, &verbose_flag, 0},
/* These options don't set a flag.
We distinguish them by their indices. */
{"add", no_argument, 0, 'a'},
{"append", no_argument, 0, 'b'},
{"delete", required_argument, 0, 'd'},
{"create", required_argument, 0, 'c'},
{"file", required_argument, 0, 'f'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "abc:d:f:", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
}
Manque de pot, ça ne compile pas...
J'ai vite trouvé qu'en changeant long_options[] par *long_options, ça compilait mieux, mais ce n'est pas encore ça :
statistic.c:849: warning: braces around scalar initializer
statistic.c:849: warning: (near initialization for ‘long_options’)
statistic.c:849: warning: initialization from incompatible pointer type
statistic.c:849: warning: excess elements in scalar initializer
statistic.c:849: warning: (near initialization for ‘long_options’)
statistic.c:849: warning: excess elements in scalar initializer
statistic.c:849: warning: (near initialization for ‘long_options’)
statistic.c:849: warning: excess elements in scalar initializer
statistic.c:849: warning: (near initialization for ‘long_options’)
Et ça, pour chaque ligne du tableau long_opts

Il n'y a pas un moyen d'avoir un truc qui marche vraiment ? (j'ai essayé un certain nombre de trucs, mais rien ne passait... et je ne suis pas un dieu des structures en C

)