Chapter 20: Getting Input from the Command Line
Up until this point, we have not read any input for any of our programs from any source. All program data has been hardcoded in the program itself. In this chapter, we will begin exploring programming input with one of the simplest available methods—inputting from the console's command line.
We will revisit the main()
function with our added knowledge of function parameters and arrays of strings. We will then explore how to retrieve strings via an argument to the main()
function.
The following topics will be covered in this chapter:
- Understanding the two forms of
main()
- Understanding how
argc
andargv
are related - Writing a program to retrieve values from
argv
and printing them - Understanding how to use
getopt()
for simple command-line processing
So, let's dive right in!