arguments parser

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if (argc < MIN_REQUIRED) {
return help();
}
int i;
/* iterate over all arguments */
for (i = 1; i < (argc - 1); i++) {
if (strcmp("-s", argv[i]) == 0) {
/* do something with it */
printf("string = %s\n", argv[++i]);
continue;
}
if (strcmp("-n", argv[i]) == 0) {
/* do something with it. for example, convert it to an integer */
printf("number = %i\n", atoi(argv[++i]));
continue;
}
if (strcmp("-true", argv[i]) == 0) {
printf("true activated\n");
continue;
}
return help();
}