getopt-long

getopt does not parse optional arguments to parameters

纵然是瞬间 提交于 2019-11-27 07:12:16
In C, getopt_long does not parse the optional arguments to command line parameters parameters. When I run the program, the optional argument is not recognized like the example run below. $ ./respond --praise John Kudos to John $ ./respond --blame John You suck ! $ ./respond --blame You suck ! Here is the test code. #include <stdio.h> #include <getopt.h> int main(int argc, char ** argv ) { int getopt_ret, option_index; static struct option long_options[] = { {"praise", required_argument, 0, 'p'}, {"blame", optional_argument, 0, 'b'}, {0, 0, 0, 0} }; while (1) { getopt_ret = getopt_long( argc,

getopt does not parse optional arguments to parameters

落爺英雄遲暮 提交于 2019-11-26 17:36:58
问题 In C, getopt_long does not parse the optional arguments to command line parameters parameters. When I run the program, the optional argument is not recognized like the example run below. $ ./respond --praise John Kudos to John $ ./respond --blame John You suck ! $ ./respond --blame You suck ! Here is the test code. #include <stdio.h> #include <getopt.h> int main(int argc, char ** argv ) { int getopt_ret, option_index; static struct option long_options[] = { {"praise", required_argument, 0, 'p