Romeo
Romeo

Reputation: 147

need suggestions on how to setup getopt_long to properly pass command line arguments

Folks, I went over example of using get_opt_long here: https://linux.die.net/man/3/getopt_long_only And I am still confuse on how to utilized in my case. I have multiple options in my case.

-Aa => ask for all
-As => ask for stats
-Af => ask for file
-seed => pass seed
-num => repeat times

I can get -seed and -num to work, but not sure how to incorporate -Ap, -Ax -Af

here is my option struct:

enter code here
{"seed"              , required_argument , NULL , 's'} , 
{"num"               , required_argument , NULL , 'n'} , 
{"ask_all"           , no_argument       , NULL , 'a'} , 
{"ask_stat"          , no_argument        , NULL ,  't'} , 
{NULL                , 0                 , NULL , 0}

also, how can I use -Ap, -As as command line argument. I am force to use unic character for all my options.

my while block has

case 's':
  seed = atoi(optarg);
  break;
case 'n':
  num = atoi(num);
case 'a':
  ask->all = true;   
  break;

Thanks

Upvotes: 0

Views: 47

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409166

Two possible solutions:

  1. Use long arguments for "Aa", "As" and "Af"
  2. Use one short argument 'A' which takes a required argument that is the 'a', 's' or 'f' character

Upvotes: 1

Related Questions