getopt
uses global variables to store the argument index, the next character to parse and some other information. Each time you call getopt
, the function checks these variables to know where it last was (or where you told it it was) and updates the variables for the next call.
Most importantly, optind
stores the index in argv
of the next element to be scanned.