If you want to scan multiple vectors you need to reset getopt
by setting optind
to 1.
The variable optind is the index of the next element of the argv[] vector to be processed. It shall be initialized to 1 by the system, and getopt() shall update it when it finishes with each element of argv[].
If setting optind
to 1 doesn't work, also try 0
, I think I remember reading about that somewhere.