HP Pascal/iX Programmer's Guide (31502-90023)
3-: 13
VAR
f1,f2,f3 : seqfile;
c1,c2 : char;
BEGIN
reset(f1); {Opens f1 for sequential input.
First component of f1 becomes its current component.}
c1 := f1^; {Assigns f1's first component to f1's buffer.
Assigns f1's buffer (first component) to c1.}
get(f1); {Advances f1's current position index.
Second component of f1 becomes its current component.}
read(f1,c2); {Implicit reference to f1's buffer --
deferred get from get(f1) assigns
f1's current (second) component to f1's buffer.
Read(f1,c2) assigns f1's current (second) component to c2
and advances f1's current position index.
Third component of f1 becomes its current component.}
rewrite(f2); {Opens f2 for sequential output (write-only).
Erases old contents.
Leaves f2's buffer undefined.}
get(f2); {Illegal -- rewrite(f2) made f2 write-only.}
f2^ := c1; {Assigns c1 to f2's buffer.}
put(f2); {Assigns f2's buffer (c1) to f2's current (first) component.
Advances f2's current position index to position two,
where its second component will be after write(f2,c2).}
write(f2,c2); {Assigns c2 to f2's current (second) component.
Advances f2's current position index to position three,
where its third component will be.}
append(f3); {Opens f3 for sequential output (write only).
Does not erase old contents, which end with component n.
Leaves f3's buffer undefined.}
(
Example is continued on next page
.)
get(f3); {Illegal -- append(f3) made f3 write-only.}
f3^ := c1; {Assigns c1 to f3's buffer.}
put(f3); {Assigns f3's buffer (c1) to f3's current (n+1st) component.
Advances f3's current position index to position n+2,
where its n+2nd component will be after write(f3,c2).}
write(f3,c2); {Assigns c2 to f3's current (n+2nd) component.
Advances f3's current position index to position n+3,
where its n+3rd component will be.}
END.
The preceding program reads values from the first and second components
of the file f1 into the variables c1 and c2 (respectively). Then it
writes c1 and c2 to the first and second components of the file f2
(respectively), and appends them to the file f3.
The get associated with read is implicit; your program need not call get
explicitly. If it does, a component is skipped.
Example 2
PROGRAM prog;
TYPE
intfile = FILE OF integer;