title: getopt_long() -- proper way to use it?
body: <p>OK, I have searched and found the following two StackOverflow topics that started me in the right direction:</p>
  
  <p><a href="https://stackoverflow.com/questions/189972/argument-parsing-helpers-for-c-unix/">Argument-parsing helpers for C/UNIX</a></p>
  
  <p><a href="https://stackoverflow.com/questions/498320/pass-arguments-into-c-program-from-command-line">Pass arguments into C program from command line</a></p>
  
  <p>NOTE: ALL CODE IS PSEUDO-CODE. WILL POST COMPILABLE CODE WHEN IT WORKS.</p>
  
  <p>However, I'm still completely confused on how to use getopt_long() in C. The program I'm writing is defined as having the following possible tags (but can include as many as you absolutely need, filling the rest in with empty values):</p>
  
  <pre><code>id3tagEd filename -title "title" -artist "artist" -year 1991 -comment "comment" -album "album" -track 1
  </code></pre>
  
  <p>Now, from what I read, I need to utilize a struct for the long options, correct? If so, I wrote something along the lines of this:</p>
  
  <pre><code>struct fields field =
  {
      char *[] title;
      char *[] artist;
      char *[] album;
      int year;
      char *[] comment;
      int track;
  }
  
  
  static struct options long_options[] =
  {
      {"title", 0, &amp;field.title, 't'},
      {"artist", 0, &amp;field.artist, 'a'},
      {"album", 0, &amp;field.album, 'b'},
      {"year", 0, &amp;field.year, 'y'},
      {"comment", 0, &amp;field.comment, 'c'},
      {"track", 0, &amp;field.track, 'u'},
      {0, 0, 0, 0}
  }
  </code></pre>
  
  <p>Now, from what I gathered, I would be calling it via this:</p>
  
  <pre><code>int option_index = 0;
  
  int values = getopt_long(argc, argv, "tabycu", long_options, &amp;option_index);
  </code></pre>
  
  <p>From here, could I strictly use the field struct and do what I need to within my program? However, if this is the case, can someone explain the whole long_options struct? I read the man pages and such, and I'm just utterly confused. By rereading the man pages, I can see I can set variables to null, and should be setting all my option requirements to "required_argument"? And then setting the structs via a while() loop? However, I see optarg being used. Is this set by getopt_long()? Or is it missing from the example?</p>
  
  <p>And one last issue, I will always have an unnamed required option: filename, would I just use argv[0] to gain access to that? (Since I can assume it'll be first).</p>
  
  <p>On a side note, this is related to a homework problem, but it has nothing to do with fixing it, its more of a fundamental, have to understand argument passing and parsing in C via command line first.</p>