Lesson goal: The End-Of-File (EOF)

Previous: Reading all data from a file (2) | Home | Next: Find the total of some numbers

The issues in the past few lessons were twofold: 1) being able to start a loop to read in all data from a file and 2) knowing when to stop reading from the file.

It turns out in file-lingo, the "end of file" or "EOF" is a very common consideration. When the EOF is reached, we are at the end of a file, and there is no more data to read. If we're in a data-reading loop, it better stop when EOF is reached.

It is so common, most programming languages have a "are we we at the end of a file?" function, that works something like this:
Move the mouse over a dotted box for more information.

Let's see if we can use file-eof and a while-loop to read in all data from a file.

Now you try. __none

Type your code here:

See your results here: