using getopt() several times in program
Mark Harrison
harrison at csl.dl.nec.com
Fri May 10 03:04:28 AEST 1991
We have a main() which uses getopt() to parse the command line options,
and then call a subroutine. The subroutine receives parameters in an
argc/argv fashion, and uses getopt() to parse them.
The subroutine, however, receives -1 on its first invocation of getopt.
It turns out that the external int optind has been set to 3 by
the main program's invocation of getopt. resetting "optarg = 1;"
in the subroutine seems to fix things.
Our questions, which are not addressed by the FM, as far as we can tell:
1. Is it legal to call getopt() multiple times in a program?
2. Is resetting optarg to 1 a reliable way of handling the problem?
3. If not, how best to handle this?
This is on SunOS 4.1.1, if it matters.
--
Mark Harrison | Note: harrison at ssd.dl.nec.com and
harrison at csl.dl.nec.com | necssd!harrison are not operating at
(214)518-5050 | present. Please forward mail through the
| above address. Sorry for the inconvenience.
More information about the Comp.lang.c
mailing list