HP C/iX Library Reference Manual (30026-90004)

200 Chapter5
HP C/iX Library Function Descriptions
getopt
getopt
Gets ASCII characters from an argument vector.
Syntax
int getopt (int
argc
, char *
argv
, char *
optstring
);
extern char *
optarg
;
extern int
optind
, opterr;
Parameters
argc
An integer giving the length of the array
argv
.
argv
A pointer to the command line.
optstring
A string of recognized option letters.
Return Values
'?' An option letter is not included in
optstring
. This error message can be
disabled by setting opterr to zero.
EOF All options have been processed.
n The next option letter in
argv
, starting from argv[1] that matches a letter
in
optstring
.
optarg
An external character pointer that is set to the start of the option
argument, if any, on return from getopt.
optind
An external integer that should be initialized to one before the first call to
getopt. The
optind
value is set to the
argv
index of the next argument to
be processed on return from getopt.
Description
The getopt function returns the next option letter in
argv
that matches a letter in
optstring
. The
optstring
argument is a string of recognized option letters. If a letter in
optstring
is followed by a colon, the option is expected to have an argument that may or
may not be separated from it by white space.
On return from getopt,
optarg
points to the start of the option argument.
The getopt function places in
optind
the
argv
index of the next argument to be processed.
The external variable
optind
is initialized to 1 before the first call to getopt().
The external integer opterr enables or disables printing error messages on the standard
error device.
When all options have been processed (for example, up to the first non-option argument),
getopt returns EOF. The special option can be used to delimit the end of the options. When
this option is processed, EOF is returned and
optind
is incremented to the
argv
index