R. Brock Lynn wrote:
> 
> How do I effectively use getopt?
>
> BUGS
>       This manpage is confusing.


Do as in the example written in the manpage. It explains the usage much
better than any words (if you ignore the _long parts).

If you rather read words, read the info page (getopt is documented in
glibc info pages), but I find that reading code is much easier..

Basic idea:

You call getopt() to find out the next option on the command line.
getopt() returns EOF when there is no more options.

Any option argument is returned in char *optarg.

The syntax for the options-string sent to getopt() is 

<char>          A "toggle" (no argument)
<char>:         Argument required
<char>::        Argument allowed but not required (optarg NULL if no argument)

Example:
"ab:c::" 
accepts
  -a                    # no argument
  -b something          # requires a argument
  -c [something]        # argument not required

---
Henrik Nordström

Reply via email to