-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
49 lines (42 loc) · 1.14 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
int main(int argc, char *argv[])
{
int opt;
int opt_index; // not going to be used as every long command
// has a corresponding short command
int aflag = 0, bflag = 0, cflag = 0;
char *cvalue = NULL;
printf("Hello World!\n");
const struct option long_options[] =
{
{"a-option", no_argument, 0, 'a'},
{"b-option", no_argument, 0, 'b'},
{"c-option", required_argument, 0, 'c'},
{0, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, "abc:",
long_options, &opt_index)) != -1) {
switch(opt)
{
case 'a':
aflag = 1;
break;
case 'b':
bflag = 1;
break;
case 'c':
cflag = 1;
if(optarg != NULL)
cvalue = optarg;
break;
default:
break;
}
}
printf("aflag = %d, bflag = %d, cflag = %d optarg = %s\n",
aflag, bflag, cflag, cvalue);
return 0;
}