02-11-07 12:18 AM
Hello Kenny,
> (since it uses global variables to track its internal state), getopt()
> seems, by design, to be only usable once. But it is not too hard to
> imagine situations where you'd want to call it multiple times in a given
> program. Is this possible (in any at least psuedo-portable way) ?
>
> (answering my own question), I have found that setting optind to 1,
> seems to work. That is, I do:
>
> #include <getopt.h>
> ...
> do normal getopt() stuff;
> ...
> optind = 1;
> do getopt() again;
Seems to be the way to go... You may want to reset opterr and optopt
as well.
Cheers,
Loic.
[ Post a follow-up to this message ]
|