I'd like to get more optargs after arguments, but I'm not sure how to do it. I want to call my program like
./test -a first second -b third
and I can now get only one value after argument -a. When I try to put there two or more, avalue is null.
My code:
char *avalue = NULL;
char *bvalue = NULL;
while ((c = getopt (argc, argv, "a:b:")) != -1)
switch (c)
{
case 'a':
avalue = optarg;
break;
case 'b':
bvalue = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort ();
}
printf ("avalue = %s\nbvalue = %s\n",avalue, bvalue);