O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

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

Command-Line Arguments

Before the modern graphical interface, there was the command-line interface. DOS and UNIX are examples. The command line is the line you type to run your program in a command-line environment. Suppose you have a program in a file named fuss. Then the command line to run it might look like this in UNIX:

$ fuss

Or it might look like this in DOS:

C> fuss

Command-line arguments are additional items on the same line.

% fuss -r Ginger

A C program can read those additional items for its own use (see Figure 11.7).

Figure 11.7. Command-line arguments.

A C program reads these items by using arguments to main(). Listing 11.27 ...

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