24,854
社区成员
发帖
与我相关
我的任务
分享
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <getopt.h>
static struct option long_options[] =
{
{"reqarg", required_argument, NULL, 'r'},
{"optarg", optional_argument, NULL, 'o'},
{"noarg1", required_argument, NULL, 'N'},
{"noarg", required_argument, NULL, 'n'},
{NULL, 0, NULL, 0},
};
int main(int argc, char *argv[])
{
int opt;
int digit_optind = 0;
int option_index = 0;
char *string = "A::b:c:N";
while((opt =getopt_long_only(argc,argv,string,long_options,&option_index))!= -1)
{
printf("opt = %c\t\t", opt);
printf("optarg = %s\t\t",optarg);
printf("optind = %d\t\t",optind);
printf("argv[optind] =%s\t\t", argv[optind]);
printf("option_index = %d\n",option_index);
}
}