Using the getopt() function in C, you can do this:
program -a arg_for_a -b arg_for_b -c operand1 operand2
and it works without problems.
But how to make it work this way ?:
program operand1 operand2 -a arg_for_a -b arg_for_b -c
In this case, each argument, including -a , -b , etc., is considered an operand.
I am trying to make it like gcc or ssh does:
gcc code.c -o executable ssh user@host -i file.pem
That is, regardless of the position in which the options and operands are, they are recognized properly.
How to correctly determine the parameters, wherever they are, and each word that does not follow the option must be recognized by the operand?
source share