File name as command line argument

The following example program must be executed with a command line argument representing the name of the text file we wish to read. The file must contain integers, separated by either a space or a newline. Reading will be halted when a nonnumeric value is encountered of the file has ended.

The program uses basic error checking – it validates the number of command line arguments, checks if the file opened successfully, checks the data it reads from the file. The example code is not able to distinguish between successfully reading until the end of the fileĀ  or encountering an error reading it (e.g. file had an alphabetical character).