HP Pascal/iX Programmer's Guide (31502-90023)

3-: 15
VAR
f : seqfile;
i : integer;
a : ARRAY [1..100] OF real;
BEGIN
reset(f); {Open f}
i := 1;
WHILE not eof(f) AND (i<=100) DO {Read array values from f}
BEGIN
read(f,a[i]);
i := i+1;
END;
END;
END.
If
f
is a terminal, the appropriate action for
eof
is a device read. The
next
read
or
readln
of
f
accesses the component in the buffer, without
performing another device read.
Example 4
PROGRAM prog (input); {for this example, assume input is from terminal}
TYPE
readbuf = PACKED ARRAY [1..80] OF char; {for device read}
VAR
x : char;
i : 1..100;
a : readbuf;
BEGIN
i := 1;
WHILE (NOT eof) AND (i <= 100) DO
BEGIN
readln(a); {perform device read}
i := i + 1;
END;
END.
By default, eof and readln apply to the standard textfile input. The
user running the program terminates input by pressing RETURN. An input
line can have up to 80 characters.
Textfile Input/Output
Textfile input/output
is sequential input/output that is performed with
textfiles (a subset of sequential files). The program reads textfile
input from read-only textfiles opened by the procedure reset, or from the
standard textfile
input
. The program writes textfile output to
write-only textfiles opened by the procedure rewrite or append, or to the
standard textfile output.
Table 3-6 summarizes the characteristics of the predefined textfile
input/output procedures.