Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!cse!texas!harrison From: harrison@csl.dl.nec.com (Mark Harrison) Newsgroups: comp.lang.c Subject: using getopt() several times in program Message-ID: <1991May9.170428.8622@csl.dl.nec.com> Date: 9 May 91 17:04:28 GMT Organization: NEC America, C & C Software Development Laboratory Lines: 21 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@ssd.dl.nec.com and harrison@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.