0

If I define

static struct option long_option[]={ {"add", 1, 0, 'a'} }

can I store two values in the optarg? This is the code what I want to use:

./a.out --add Tommy 123-123-123

and I would like to store two values, Tommy and 123-123-123 by using --add once.

1 Answers1

0

I'm afraid you can't. According to getopt man page, getopt uses next argument. So you can :

  • either use ./a.out --add 'Tommy 123-123-123' and the quotes makes the shell take 'Tommy 123-123-123' as a single argument
  • or program by hand your own option parser
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252