O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing the Command Line

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

/​/​ ​d​u​m​p​a​r​g​s​.​m​ ​-​-​ ​s​h​o​w​ ​p​r​o​g​r​a​m​ ​a​r​g​u​m​e​n​t​s​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required