Is there an alternative way to pass two arguments to an option as a single string when using getopt()
? Normally I would do the following:
./command -o "key value" [command arguments]
Then I would have to split the argument string explicitly:
while ((op = getopt(argc, argv, "o:")) != EOF) {
switch (op) {
case 'o':
char* result = NULL;
result = strtok_r(optarg," ");
while(result) {
/* DO STUFF */
result = strtok(NULL," ");
}
break;
default:
printUsage()
break;
}
So, I am wondering if it is possible to use the following and make getopt()
treat "value" as -o
second argument rather than the command argument?
./command -o key value [command arguments]