some more relevant info from the getopt() manpage.
The getopt() function shall return the next option character (if one is found) from argv that
matches a character in optstring, if there is one that matches. If the option takes an argument,
getopt() shall set the variable optarg to point to the option-argument as follows:
+ If the option was the last character in the string pointed to by an element of argv, then optarg
shall contain the next element of argv, and optind shall be incremented by 2. If the resulting
value of optind is greater than argc, this indicates a missing option-argument, and getopt()
shall return an error indication.
+ Otherwise, optarg shall point to the string following the option character in that element of
argv, and optind shall be incremented by 1