I am having trouble using getopt_long() function with custom argc and argv.
I receive my arguments in a string instead of the real command line args. Then a new_argc and new_argv was built from this string to be used with getopt_long(). But getopt_long() fails on the first call itself. returns EOF and optarg = NULL.
string is "-c 10.30.99.41"
new_argc = 3
new_argv[0]=>./prog_name
new_argv[1]=>-c
new_argv[2]=>10.30.99.41
getopt_long works OK for me if I pass command line args. So my short and long options are correct. But if I pass the new_argc and new_argv it fails.
I am sure my short and long options are right and the argv is NULL terminated. I apologize I cant post more code here.
I doubt if getopt_long can be used with a custom argc and argv. I suspect it works only with a real argc and argv because it must be referencing some other code in libc related to argc,argv. Any comments?
option = getopt_long( new_argc, new_argv, short_options, long_options, NULL );