HP Pascal/iX Programmer's Guide (31502-90023)
3- 14
VAR
f : intfile;
x,y,z : integer;
BEGIN
reset(f); {Opens f for sequential input.
First component becomes current component.}
read(f,x); {Implicit reference to f's buffer -- deferred get
from reset(f), above -- assigns current (first)
component to buffer. Then read(f,x) assigns
current (first) component to x.
Second component becomes current component.}
read(f,y); {Implicit reference to buffer --
deferred get from read(f,x) assigns
current (second) component to buffer.
Read(f,y) assigns current (second) component to y
and advances current position pointer.
Third component becomes current component.}
get(f); {Explicit reference to buffer --
because get(f) follows read(f,y),
it advances the current position pointer.
Fourth component becomes the current component.}
read(f,z); {Implicit reference to buffer --
deferred get from get(f) assigns current (fourth)
component to buffer.
Read(f,z) assigns current (fourth) to z.
Fifth component becomes the current component.}
END.
The preceding program assigns the first, second, and fourth components of
the file f to the variables x, y, and z, respectively. The program skips
the third component.
Table 3-5 gives the characteristics of the predefined sequential file
functions.
Table 3-5. Characteristics of Sequential File Functions
-----------------------------------------------------------------------------------------------
| | | |
| Function | Eof | Position |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Returns: |
True
if the current position index is at | Current position index |
| | the end-of-file marker;
false
otherwise | (an integer). |
| | (always
true
for a write-only file). | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Effect on buffer: | If
eof
returns false, and the buffer does | None. |
| | not have a value, then
eof
assigns the | |
| | value of the current component to the | |
| | buffer; otherwise, no effect. | |
| | | |
-----------------------------------------------------------------------------------------------
Trying to read from file f when eof(f) is
true
causes a run-time error.
You can prevent it by calling eof(f) before attempting to read from f,
and taking appropriate action if eof(f) is
true
.
Example 3
PROGRAM prog;
TYPE
seqfile = FILE OF real;