Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- libc - <b>getopt</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
getopt
======

Syntax
------

     int getopt(int argc, char * const *argv, const char *options);
     extern char *optarg;
     extern int optind, opterr;
     extern char optopt;

Description
-----------

Parse options from the command line.  The OPTIONS are a string of valid
option characters.  If a given option takes a parameter, that character
should be followed by a colon.

For each valid switch, this function sets `optarg' to the argument (if
the switch takes one), sets `optind' to the index in ARGV that it is
using, sets `optopt' to the option letter found, and returns the option
letter found.

If an unexpected option is found, `getopt' will return `?', and if
`opterr' is nonzero, will print an error message to stderr.

The special option `--' indicates that no more options follow on the
command line, and cause `getopt' to stop looking.

Return Value
------------

The option found, or -1 if no more options.

Example
-------

     int c;
     opterr = 0;
     while ((c=getopt(argc, argv, "vbf:")) != -1)
     {
       switch (c)
       {
         case 'v':
           verbose_flag ++;
           break;
         case 'b':
           binary_flag ++;
           break;
         case 'f':
           output_filename = optarg;
           break;
         case '?':
           printf("Unknown option %c\n", c);
           usage();
           exit(1);
       }
     }


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson