I am wondering the best way to process multiple command line arguments. I have seen command line arguments done with switch and case statements like this:
while ((x = getopt(argc, argv, "bic:")) != -1){
switch (x){
case 'b':
//do something
break;
case 'i':
//do something
break;
case 'c':
//do something
break;
default:
break;
}
This works fine. However, It doesn't lend itself very well to working with multiple command line arguments. For the project I'm working on if I enter multiple arguments I would want that to be a combination of the two cases, if that makes sense. So the division between cases is a bit annoying... I guess I could make separate cases for each combination, like case: 'ib'
or case: 'ibc'
But is there a simpler solution?
Also, I am trying to find a solution where it doesn't matter the order of arguments entered. a.out -b -c
should be the same as a.out -c -b
Copyright Notice:Content Author:「mjones」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28014668/multiple-command-line-arguments-in-c