Differences between current version and revision by previous author of getopt(3).
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 7 | Last edited on Tuesday, November 9, 2004 9:41:04 am | by DanielLawson | |
Older page: | version 6 | Last edited on Thursday, October 7, 2004 11:00:26 am | by SamJansen | Revert |
@@ -318,4 +318,32 @@
is set. Otherwise, the elements of ''argv'' aren't really
const, because we permute them. We pretend they're const in
the prototype to be compatible with other
systems.
+
+----
+
+!NOTES
+
+! getopt keeps internal state
+
+If you want to use getopt more than once within a program, across different inputs, you'll need to reset its internal state counters before
+each use:
+
+<pre>
+ printf("%d %d %d\n",optind,opterr,optopt);
+ ... do getopt stuff ...
+ printf("%d %d %d\n",optind,opterr,optopt);
+</pre>
+
+This outputs the following:
+
+<pre>
+1 1 63
+3 1 63
+</pre>
+
+the '3' in my case is because I only had one option + parameter (+ program name == 3).
+
+So, if you reset optind, opterr and optopt to 1, 1 and 63, before each new use of getopt, you should be fine.
+
+-- DanielLawson