Bonjour,
J'ai un probleme avec la fonction getopt_long, voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
static struct option long_options[] =
    {
      {"version", 0, NULL, 0},
    };
 
  while ((c = getopt_long(argc, argv, "c:",
                          long_options, &option_index)) != -1)
    if (c == 0)
      {
          if (strcmp( "version", long_options[option_index].name) == 0)
          printf("version 0.5\n");
      }
    else if ( c == 'c')
      printf("command read : %s\n", optarg);
Je suis capable de gerer des options longues et courtes,
par exemple, si j'ecrit : , il est affiche version 0.5 comme prevu. Le probleme est que le parsing est trop "laxiste", si j'ecrit --v ou --ver, long_options[option_index].name sera toujours egal a version. Comment obliger getopt a n'accepter que l'argument exact --version ?

Merci de votre aide