Add command line switches to console application

I have made a small app that is menu driven; so when the program launches it looks like the code snippet below:
1
2
3
4
  1. Choice 1
  2. Choice 2
  3. Choice 3
  4. Choice 4


So far so good, and all my "Choices" work. Each Choice listed has its own choices (1-4) with in it as well. So what I would like to do is add some command line switch capability to the program. So that when I execute from a command line like this: "myapp.exe -p", it would execute the 1st choice within Choice 1. Running "myapp.exe -m", might run choice 3 from choice 4, etc.

Any help with this would be GREAT. Just like my name implies, I am a total newb at this, everything I have done so far has been by looking for examples of what I need and then modifying to fit my needs better.
Thanks for that link.. That helped me get the usage screen that was going to be my next step.
However I am still having trouble figure out how to make the command line option -A execute one of my functions we'll say "void choice12".

Because I'm totally new at this I need concrete examples, SORRY.
It works just like any other variable.
1
2
3
4
5
6
7
8
9
10
11
switch(argv[1])
{
    case 'A':
        choice12(argv[2]);
        return;
    case 'B':
        // do something else
        return;
    default:
        // do default stuff
}


I forget off hand how optional arguments work so it might be a little different if you have them as options.
Last edited on
Topic archived. No new replies allowed.