[OCLUG-devel] getopts

Christopher Smith x at xman.org
Thu Jul 14 12:45:53 PDT 2005


Doug Jolley wrote:
> I'm assuming that there must exist a C library function for parsing
> command line arguments similar to the bash getopts builtin command. 
> In fact, I wouldn't be surprised if the C function served as the basis
> of all such functions.  Anyway, can someone tell me where to find this
> function and info on how to use it?  Thanks.

Very good guess:

http://www.opengroup.org/onlinepubs/007908799/xsh/getopt.html

Not part of C, but part of POSIX.

GNU provides getopt, getopt_long and argp:

http://www.gnu.org/software/libc/manual/html_node/Parsing-Program-Arguments.html#Parsing-Program-Arguments

I've never used argp, but it's supposed to be better.

These days I'm mostly doing C++, so I used the Boost.Program_options
library instead:

http://www.boost.org/doc/html/program_options.html

--Chris


More information about the OCLUG-devel mailing list