2

Using the same program, but with the < operator to redirect input, you can print the file on the terminal:

hostname% copy < data hello, are you listening? goodbye, I must go now.

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:

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 }

12

Pascal 4.0 User’s Guide