The eof function tests whether a file is at end-of-file, and returns a value of boolean type that indicates the result of the test. If the file tested is at end-of-file then the value true is returned, and if the file tested in not at end-of-file then the value false is returned.
The eof function's optional parameter is a reference to a file variable. If the optional parameter is supplied then the eof function tests the file associated with the parameter. If the optional parameter is not supplied then the file associated with the built-in variable input is tested.
The function below counts the number of lines in a text file. The eof function is used to determine when the end of the text file has been reached.
function CountLines(name : filename) : integer; var count : integer; f : text; begin count := 0; reset(f, name); while not eof(f) do begin readln(f); inc(count); end; CountLines := count; close(f) end;
Operating Systems: All Standard Pascal: Yes