www.delorie.com/gnu/docs/glibc/libc_523.html   search  
 
Buy the book!


The GNU C Library

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

25.1.2 Parsing Program Arguments

If the syntax for the command line arguments to your program is simple enough, you can simply pick the arguments off from argv by hand. But unless your program takes a fixed number of arguments, or all of the arguments are interpreted in the same way (as file names, for example), you are usually better off using getopt (see section 25.2 Parsing program options using getopt) or argp_parse (see section 25.3 Parsing Program Options with Argp) to do the parsing.

getopt is more standard (the short-option only version of it is a part of the POSIX standard), but using argp_parse is often easier, both for very simple and very complex option structures, because it does more of the dirty work for you.

25.2 Parsing program options using getopt  
25.3 Parsing Program Options with Argp  Parsing program options using argp_parse.
25.3.12.1 Parsing of Suboptions  Some programs need more detailed options.
25.3.13 Parsing of Suboptions Example  This shows how it could be done for mount.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003