Order of getopt () arguments in C

0

I need to use two arguments with one parameter each, only that in case of grouping them the parameter serves for the two arguments.

For example:

miprograma -a 45

miprograma -b 45

miprograma -ab 45

I do not know if it is understood, I already probe with:

getopt (argc, argv, "ab:")

getopt (argc, argv, "ab:a:b:")

and they do not work, I already appreciate the help.

    
asked by Mauro 24.10.2018 в 15:19
source

1 answer

1

first of all, thank you very much to all who collaborated. I managed to implement what I needed using getopt () with a different order in the Mask I use to parse. Instead of using this order:

getopt (argc, argv, "ab:a:b:")

implement the mask in this order:

getopt (argc, argv, "a:b:ab")

and it works as expected, entering a single argument with a single parameter and entering the two arguments and a single time the parameter. These 3 conventions work:

miprograma -a 45

miprograma -b 45

miprograma -ab 45

Greetings.

    
answered by 25.10.2018 в 00:39