Last active
August 29, 2015 14:26
-
-
Save mengqingzhong/8b202ca3e8e61b2fdde9 to your computer and use it in GitHub Desktop.
option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include <getopt.h> | |
int flag; | |
struct option long_options[] = { | |
{ "deamon", no_argument, NULL, 'D' }, | |
{ "loglevel", required_argument, NULL, 'L' }, | |
{ "ip", required_argument,&flag, 1 }, | |
{ "port", required_argument, &flag, 2 }, | |
}; | |
int main(int argc, char**argv) { | |
int option_index = 0; | |
while (1) { | |
int c = getopt_long(argc, argv, "DL:", long_options, &option_index); | |
if (c == -1) { | |
break; | |
} | |
switch (c) { | |
case 'D': | |
printf("D\n"); | |
break; | |
case 'L': | |
printf("L %s\n", optarg); | |
break; | |
case 0: | |
switch (flag) { | |
case 1: | |
printf("flag 1 %s\n", optarg); | |
break; | |
case 2: | |
printf("flag 2 %s\n", optarg); | |
break; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./a.out -D -L 8 --ip ljljk --port 23 --port 46