Read the input file

Listing 2 performs the following tasks:

You saw code similar to this in the earlier lesson entitled One-Dimensional Arrays.

In that lesson, the five values were read from the keyboard instead of being read from a file.

If you compare the code in Listing 2 to the code in Listing 3 in the earlier lesson, you will see that there is very little difference in reading data from the keyboard and reading data from a file once the file is opened for reading as shown in Listing 1.