
Analysis
■
At line 26, the getopt() function is declared.
■
At lines 28 through 31, local variables are declared that are used for parsing the
command-line option and option specifier string.
■
At lines 38 through 70, the command-line arguments are parsed based upon
the option specifier string, with the option specified being returned from the
function, and optionally the value for the option being assigned to the optarg
global variable.
Example 6.30 shows code for the getopt test program.
Example 6.30 getopt Test Program (main.c)
1 /*
2 * main.c
3 *
4 * Win32 getopt example
5 */
6
7
#include <stdio.h>
8 #include "getopt.h"
9
10
int
11 main(int argc, char *argv[])
12