program -n 2 -t 4 -- text
.--
?#include <getopt.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct option longopts[] =
{
{
.name = "number",
.has_arg = required_argument,
.flag = NULL,
.val = 'n'
},
{
.name = "timeout",
.has_arg = required_argument,
.flag = NULL,
.val = 't'
},
{
.name = "",
.has_arg = required_argument,
.flag = NULL,
.val = 0
}
};
while (1)
{
int c = getopt_long(argc, argv, "n:t:", longopts, NULL);
if (c == -1)
{
break;
}
switch (c)
{
case 'n':
printf("option 'n' with '%s'\n", optarg);
break;
case 't':
printf("option 't' with '%s'\n", optarg);
break;
case NULL:
printf("def");
break;
}
}
return 0;
}