Home > Articles

  • Print
  • + Share This
This chapter is from the book

2.5 Summary

  • C programs access their command-line arguments through the parameters argc and argv. The getopt() function provides a standard way for consistent parsing of options and their arguments. The GNU version of getopt() provides some extensions, and getopt_long() and getopt_long_only() make it possible to easily parse long-style options.

  • The environment is a set of 'name=value' pairs that each program inherits from its parent. Programs can, at their author's whim, use environment variables to change their behavior, in addition to any command-line arguments. Standard routines (getenv(), setenv(), putenv(), and unsetenv()) exist for retrieving environment variable values, changing them, or removing them. If necessary, the entire environment is available through the external variable environ or through the char **envp third argument to main(). The latter technique is discouraged.

  • + Share This
  • 🔖 Save To Your Account