End of File and End of Line
EOF
Accepts the name of the input file, and returns true if there is
no more data to be read.
EOLN
Accepts the name of the input file, and is true if there are no
more characters on the current line.
When reading information from a text file, the character which is read can be compared against EOLN or EOF. Consider the following program which displays the contents of a text file on the console screen.
program SHOWTEXT ( infile, input, output ); var ch : char; fname : packed array [1..15] of char; infile: TEXT; begin writeln('Please enter name of text file to display.'); readln( fname ); reset( infile, fname ); {open a file using filename stored in} {array fname } while not eof( infile ) do begin while not eoln( infile ) do begin read( infile, ch ); write( ch ) end; readln( infile ); {read eoln character} writeln {write eoln character} end; close( infile ) {close filename specified by fname} end.
PROGRAM TWENTY-TWO
Write a program to count the number of words in a text file.