Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e1b7b2

Browse files
committed
Add getopt_long example code
Signed-off-by: Seungha Son <seungha.son@samsung.com>
1 parent f34c527 commit 6e1b7b2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎getopt/getopt_long.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <getopt.h>
4+
5+
static const char *optstring = "o:hv";
6+
7+
static const struct option long_options[] = {
8+
{ "out", required_argument, NULL, 'o' },
9+
{ "help", no_argument, NULL, 'h' },
10+
{ "version", no_argument, NULL, 'v' },
11+
{ NULL, 0, NULL, 0 }
12+
};
13+
14+
int main(int argc, char *argv[])
15+
{
16+
char optc;
17+
18+
while ((optc = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
19+
switch (optc) {
20+
case 'o':
21+
printf("out argument : %s\n", optarg);
22+
break;
23+
case 'h':
24+
printf("help");
25+
break;
26+
case 'v':
27+
printf("version");
28+
break;
29+
default:
30+
break;
31+
}
32+
}
33+
34+
return 0;
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /