title: How to judge the value of optind in getopt
body: <p>I just want to test global variable optind and do the following test.How to judge the value of optind?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char *argv[])
  {
      char optStr[] = "ab";
      int c;
  
      while ((c = getopt(argc, argv, optStr)) != -1) {
          printf("optind: %d\n", optind);
          switch (c) {
              case 'a':
                  printf("-a\n"); 
                  break;
              case 'b':
                  printf("-b\n"); 
                  break;
              case '?':
                  printf("error\n");
                  break;
            }
        }
  
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>./a.out -ab <br/><br/>
    optind: 1 <br/>
    -a <br/>
    optind: 2<br/>
    -b <br/></p>
  </blockquote>
  
  <p>next:</p>
  
  <blockquote>
    <p>./a.out -a <br/><br/>
    optind: 2<br/>
    -a</p>
  </blockquote>