-
Notifications
You must be signed in to change notification settings - Fork 297
Expand file tree
/
Copy pathoption_example.c
More file actions
36 lines (31 loc) · 801 Bytes
/
Copy pathoption_example.c
File metadata and controls
36 lines (31 loc) · 801 Bytes
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
#include "sc_option.h"
static struct sc_option_item options[] = {{.letter = 'm', .name = NULL},
{.letter = 'k', .name = "key"},
{.letter = 'h', .name = "help"}};
int main(int argc, char *argv[])
{
char *value;
struct sc_option opt = {.argv = argv,
.count = sizeof(options) / sizeof(options[0]),
.options = options};
for (int i = 1; i < argc; i++) {
char c = sc_option_at(&opt, i, &value);
switch (c) {
case 'm':
// If value does not exist, it will point to '\0'
// character.
printf("Option 'm', value : %s \n", value);
break;
case 'k':
printf("Option 'k', value : %s \n", value);
break;
case 'h':
printf("Option 'h', value : %s \n", value);
break;
case '?':
printf("Unknown option : %s \n", argv[i]);
break;
}
}
return 0;
}