6 main (int argc
, char **argv
)
8 static const struct option options
[] =
10 {"required", required_argument
, NULL
, 'r'},
11 {"optional", optional_argument
, NULL
, 'o'},
12 {"none", no_argument
, NULL
, 'n'}
21 while ((c
= getopt_long (argc
, argv
, "abc:", options
, NULL
)) >= 0)
34 fputs ("Unknown option.\n", stderr
);
37 fprintf (stderr
, "This should never happen!\n");
41 printf ("--required %s\n", optarg
);
44 printf ("--optional %s\n", optarg
);
51 printf ("aflag = %d, bflag = %d, cvalue = %s\n", aflag
, bflag
, cvalue
);
53 for (index
= optind
; index
< argc
; index
++)
54 printf ("Non-option argument %s\n", argv
[index
]);