Is there a "standard" or typical way to process command-line arguments in argv?
In the past, I've always just used simple if statements, but that is when the args needed to be provided in a specific order. I now have an assignment that requires that the application be invoked like this:
where n and q are just integers and are unrelated to each other.Code:progname -o outfile n q
The way I interpret this is that since the output file is specified with the -o switch, the arguments could be passed in any order at the CLI as long as the integers n & q are in the proper order. For example:
would be a valid call. This makes my simple if statements that check the indices of argv in a sequential manner obsolete.Code:progname n -o outfile q
I know I could handle this in several ways without much difficulty, but it might be messy. If there is a standard way to handle this situation, since so many programs use such switches, then I might as well do it properly so that I can do it this way from now on.
If someone could point me in the right direction, either with a URL, or link, a keyword to Google on, or even just an idea, it would be much appreciated.