title: C Using a file argument with GetOpt
body: <p>Is there a better way to find the name of a file than just looping through argv[] looking for an argument that isn't a flag - ?</p>
  
  <p>In this case, the flags can be entered in any order (so optind isn't going to help).</p>
  
  <p>ie:</p>
  
  <p>/program -p file.txt -s</p>
  
  <p>/program -p -s file.txt -b</p>
  
  <p>/program file.txt -p -s -a</p>
  
  <pre><code>int main (int argc, char *argv[]){
  
  
  char option;
  const char *optstring;
  optstring = "rs:pih";
  
  
  while ((option = getopt(argc, argv, optstring)) != EOF) {
  
      switch (option) {
          case 'r':
              //do something
              break;
          case 's':
            //etc etc 
     }
  }
  </code></pre>