Contents | Prev | Next

7.4.46 The readln procedure

Description

The readln procedure reads values from the file associated with a file variable of type text into one or more variables, and then skips to the beginning of the next line.

Parameters

  1. The first parameter is optional, and if supplied is a reference to the file variable associated with the file to read from. If this parameter is not supplied then the readln procedure reads values from the file associated with input.
  2. The other parameters are optional, and if supplied are references to the variables used to store the values read from the file.

Reading From Text Files

The readln procedure always reads values from a text file (i.e. a file associated with a file variable of type text), and the way the values are read is determined by the type of the variable used to store the values.

Example

For example the program "batch.pas" below is a very primitive batch processor. It reads lines from a text file using "readln" and send the lines to the command processor to be executed.

   program batch(f, output);
   var
      f : text;
      s : string;
      err : integer;
   begin
      reset(f);    (* open input file or standard input file *)
      while not eof(f) do
      begin
        readln(f, s);
        writeln('Executing ', s);
        err := system(s);      (* Pass 's' to the command processor *)
        writeln('Error code is ', err)
     end
   end.

Portability

Operating Systems: All
Standard Pascal: Yes

Standard Pascal does not support reading from text files into variable of string type.

Contents | Prev | Next