for example,
I have the structure options as following:
struct option options[] = {
{"input", required_argument, NULL, OPT_INPUT},
{"flag", no_argument, NULL, OPT_FLAG},
}
Now,if a user of the program by mistake omits the input file-name after -input command, passes the flag, like this:
./program -input -flag
The getopt_long_only treats "-flag" as the argument for input, thus taking it as the input file in the program, and not the next argument (and hence returning error for no argument being passed after -input). How can this be avoided?
I am using GUN/LINUX (2.6.34.3) and gcc (GCC) 4.4.2 20091027 (Red Hat 4.4.2-7).