roy@phri.UUCP (Roy Smith) (09/07/88)
If I turn off getopt's internal error message printing by setting opterr to 0, how do I reliably find out what argument getopt is objecting to when it returns '?'? For example, let's say I have a program foo which does: opterr = 0; while ((c = getopt (argc, argv, "a")) != eof) { switch (c) { case 'a': aflag = 1; break; case '?': error ("unknown flag (%s)", argv[optind-1]); } } If I do "foo -x", sure enough I get "unknown flag (-x)". But, if I do "foo -xy", I get "unknown flag (foo)"; argv[optind] is still pointing to the "-xy" because there is more stuff after the "-x". I can't see any way around this other than to let getopt print the error message itself, which I'd rather not do for various reasons. -- Roy Smith, System Administrator Public Health Research Institute {allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net "The connector is the network"