how to use long options via getopt_long:
for example like this:
--wide-option
I have --wide and -w.
And on --wide-option it gives the following error:
"unrecognized option"
int main(int argc, char **argv)
{
struct option opts[] =
{
{"wide", 1, 0, 'w'},
{
0, 0, 0, 0
}
};
int option_val = 0;
int counter = 10;
int opindex = 0;
while ((option_val = getopt_long(argc, argv, "w:", opts, &opindex)) != -1)
{
switch (option_val)
{
case 'w':
if (optarg != NULL)
counter = atoi(optarg);
for (int i = 0; i < counter; i++)
printf("Hello world\n");
break;
default:
return 0;
}
}
return 0;
}
If you look at the
catsource code (here), you can see that--numberand--number-nonblankare two different options (-band-n). (near line 555).If you want to do the same, you can that way: