title: Parsing options having a common flag in C
body: <p>I have a C program where I accept multiple arguments. Here, I have a common flag <code>d</code> for both data-store and disk. Is there a way that I can check for the flags in-order and get the value of <code>store</code> before I check with case <code>d</code>. I've tried various ways like adding a while loop before this to check for <code>s</code> and then enter this loop etc. </p>
  
  <pre><code>static void
  ParseOptions(int argc, char* argv[])
  {
     int c, option_index;
     int ind = 0;
  
     while((c = getopt_long(argc, argv, "s:d:",
                            long_options, &amp;option_index))!= -1) {
         ind = optind;
         switch(c) {
          case 's':
              optionStore = true;
              store = strdup(optarg);
              break;
          case 'd':
              if(strcmp(store,"datastore") == 0){
                  printf("In datastore\n");
                  datastore = strdup(optarg);
              }
              else if(strcmp(store,"disk") == 0){
                  printf("In disk\n");
                  disk = strdup(optarg);
  
              }            
              break;
          default:
              exit(-1);
         }
     }
  }
  </code></pre>
  
  <p>Not sure how to go about this.   </p>