title: different order of command line options in a command affecting my output
body: <p>i am making a program in c that accepts command line arguments like --version , --download.</p>
  
  <p>when i do this :</p>
  
  <pre><code>$program --version --download file
  </code></pre>
  
  <p>the program outputs the version and downloads the file. But when i do this:</p>
  
  <pre><code>$program --download --version file
  </code></pre>
  
  <p>the program considers <code>--version</code> to be the argument to <code>--download</code>.</p>
  
  <p>I have used <code>getopt_long()</code> function for parsing the command line arguments. Here's a snippet from my code:</p>
  
  <pre><code>while ((ch = getopt_long(argc, argv, "d:g:hv", longoptions, &amp;optindex)) != -1 )
  {
      switch(ch)
      {
              case 'd' :
                  if ( optarg )
                      printf("Downloading %s...\n" , optarg);
                  iso(optarg);
                  break ;
  
              case 'g' :
                  if ( optarg )
                      printf("Downloading glug-mirror automation script for %s ...\n", optarg);
                  getscript(optarg);
                  break ; 
  
              case 'v' : 
                  printf("glug version 1.0.0 ( NIT Hamirpur)\n");
                  break ;
  
              case 'h' :
                  usage(status);
                  break ;
  
              default :
                  status  = 2 ; 
                 usage(status);
      }
  }
  </code></pre>