Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #86433

Re: getopt() function

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: getopt() function
Date 2016-04-15 11:20 -0700
Organization None to speak of
Message-ID <lnk2jyn38q.fsf@kst-u.example.com> (permalink)
References <c974cd17-7fe1-44db-9339-7bffd221378e@googlegroups.com> <2as1hb9fsg6u6b4b1k08bv5at5v2eerfno@4ax.com> <lnshymna9u.fsf@kst-u.example.com> <ci52hbd62668qtrrr44asml8ms00217o5l@4ax.com>

Show all headers | View raw


Geoff <geoff@invalid.invalid> writes:
> On Fri, 15 Apr 2016 08:48:13 -0700, Keith Thompson <kst-u@mib.org>
> wrote:
>>The program requires zero or more *options* followed by at least one
>>argument that is not an option.  (It could be a file name, for example.)
>>The "expected argument after options" message is about the lack of an
>>argument after the options, not about the lack of an argument to the -t
>>option.
>
> I disagree with your interpretation. The colon in "nt:" means it
> expects a non-optional argument to the t option. If it expected a
> non-optional argument it would be ":nt:".

I don't think that's correct.  I haven't actually used getopt()
much myself, but I don't believe the optstring specifies arguments
other than options.  That's left up to the program.

After the

    while ((opt = getopt(...)) != -1)

loop has finished, any options have been processed and any remaining
arguments are left in the argv array.  The program can then decide
whether those remaining arguments are valid, and if so how to handle
them.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

getopt() function Alla _ <modelling.data@gmail.com> - 2016-04-15 05:05 -0700
  Re: getopt() function Richard Heathfield <rjh@cpax.org.uk> - 2016-04-15 13:09 +0100
    Re: getopt() function Alla _ <modelling.data@gmail.com> - 2016-04-15 05:25 -0700
    Re: getopt() function gpietsch08618@gmail.com - 2016-04-26 22:39 -0700
      Re: getopt() function Alla _ <modelling.data@gmail.com> - 2016-04-27 00:09 -0700
        Re: getopt() function gpietsch08618@gmail.com - 2016-05-31 05:44 -0700
  Re: getopt() function Geoff <geoff@invalid.invalid> - 2016-04-15 06:58 -0700
    Re: getopt() function Alla _ <modelling.data@gmail.com> - 2016-04-15 07:54 -0700
      Re: getopt() function Richard Heathfield <rjh@cpax.org.uk> - 2016-04-15 15:58 +0100
      Re: getopt() function Geoff <geoff@invalid.invalid> - 2016-04-15 08:24 -0700
    Re: getopt() function Keith Thompson <kst-u@mib.org> - 2016-04-15 08:48 -0700
      Re: getopt() function Geoff <geoff@invalid.invalid> - 2016-04-15 09:29 -0700
        Re: getopt() function Keith Thompson <kst-u@mib.org> - 2016-04-15 11:20 -0700
    Re: getopt() function Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-04-16 16:51 -0700
      Re: getopt() function janus <emekamicro@gmail.com> - 2016-05-31 22:23 -0700
        Re: getopt() function Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-05-31 23:27 -0700
          Re: getopt() function janus <emekamicro@gmail.com> - 2016-06-01 00:27 -0700
  Re: getopt() function Geoff <geoff@invalid.invalid> - 2016-04-15 08:37 -0700
    Re: getopt() function Geoff <geoff@invalid.invalid> - 2016-04-15 08:46 -0700
      Re: getopt() function Keith Thompson <kst-u@mib.org> - 2016-04-15 12:11 -0700
        Re: getopt() function Geoff <geoff@invalid.invalid> - 2016-04-15 13:43 -0700
  Re: getopt() function Ian Collins <ian-news@hotmail.com> - 2016-04-16 08:34 +1200
    Re: getopt() function Alla _ <modelling.data@gmail.com> - 2016-04-18 08:40 -0700
      Re: getopt() function Randy Howard <rhoward.mx@EverybodyUsesIt.com> - 2016-04-18 15:20 -0500
  Re: getopt() function boon <fred900rbc@gmail.com> - 2016-04-18 06:26 -0700

csiph-web