I need to parse command options as given below in C:
./myBinary --option1 name --option2 age --option3 address
Getopt only support -l , -a kind of flags. Any suggestions?
I need to parse command options as given below in C:
./myBinary --option1 name --option2 age --option3 address
Getopt only support -l , -a kind of flags. Any suggestions?
The only solid way is parsing those arguments without depending on external libraries. There is no widely accepted standard for handling command line arguments.
The best you have is the standardised call to main
providing access to command line arguments:
int main(int argc, char *argv[]) {
}
There are major differences between operating systems, but it's worse than that.
/option
or -option
, but many tools borrow from other platforms.--option
and -o
via getopt_long
.-o
, but some applications may be ported from Linux.-option
but borrows from BSD and sometimes Linux.So only GNU provides a "standard" library for parsing such options. Consider it a non-portable extension.
Long story short: you need to provide more details about your target platform(s) to get a better answer, but don't expect some perfect solution.