FAQ Database Discussion Community

Segfault for invalid long option

I have the following code: struct option longopts[] = { {"version", no_argument, 0, 'v'} }; if (argc > 1) { int c; int longindex; while ((c = getopt_long (argc, argv, "v", longopts, &longindex)) != -1) { switch (c) { case 'v': puts (VERSION_INFO); exit (0); case '?': exit (1); }...

GetOptions Optional 2nd value to an argument

I would like an option where the first value is mandatory, and the 2nd value is optional. For example, ./foo --arg mandatory optional If I use =s{2} the user is forced to enter the second option. I don't want to allow n-number of values...I want to mandate only allowing two...

How to pass escape sequence like tab and newline char as command line argument in C programming getopt_long?

I almost reached end of my code, after a lot of search I didn't find solution no where, I want to supply escape sequence like '\t', '\n' to my program like how awk and perl program takes, and finally I want to use them as printf or sprintf format string...