August 2011
Intermediate to advanced
552 pages
23h 48m
English
Aside from reading some configuration file, the last way to influence program behavior is through command-line arguments. This is also the most common way to control program behavior for command-line programs.
Recall earlier that the “choose behavior based on program name” version of upcase looked at the first element of argv to get the program name. The argv array in fact has all of the program’s arguments, living at argv indexes greater than zero. Recall that argc is the number of arguments on the command line, including the program name.
Example 4.2 is a quick little program that prints out command-line arguments:
Example 4.2. dumpargs.m
// dumpargs.m -- show program arguments ...
Read now
Unlock full access