Using a file name as a file variable – HP SunSoft Pascal 4.0 User Manual
Page 36
Advertising

12
Pascal 4.0 User’s Guide
2
Using the same program, but with the
<
operator to redirect input, you can
print the file on the terminal:
Using a File Name as a File Variable
You can also redirect the output by listing the file as a file variable in the
program statement. The Pascal library associates the file variable with a file of
the same name. For example,
copy2.p
lists
data
as the input file variable:
hostname% copy < data
hello, are you listening?
goodbye, I must go now.
program copy2(data, output);
{ This program redirects input. }
var
c: char;
data: text;
begin
reset(data);
while not eof(data) do begin
while not eoln(data) do begin
read(data, c);
write(c)
end;
readln(data);
writeln
end
end. { copy2 }
Advertising