Contents | Prev | Next
7.4.44 The read procedure
Description
The read procedure reads values from the file
associated with a file variable into one or more
variables.
Parameters
- 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 read procedure reads values from the file
associated with input.
- The other parameters are references to the variables
used to store the values read from the file.
Reading From Text Files
If the read procedure reads values from a text file (i.e. a file associated with
a file variable of type text),
then the way the values are read is determined by the type of
the variable used to store the values.
- If a variable of
char type or a subrange
of char type is being used to store the values read from
the text file then a single character is read from the text file and this character is stored
without conversion in the variable.
- If a variable of
string type is being used to store the values read from
the text file then characters are read from the text file and stored in the
variable until either the end of the line is reached or the
number of characters stored in the variable is equal to the maximum number of characters that
can be stored in the variable.
- If a variable of an
integral type or a subrange
of an integral type is being used to store the values read
from the text file then a sequence of characters forming a signed
decimal integer number, possibly with leading
blanks, is read from the file, and converted into the
equivalent value of integer type before being stored in
the variable.
- If a variable of
real type, single type,
or double type is being used to store the values read
from the text file then a sequence of characters forming a signed
real number, possibly with leading
blanks, is read from the file, and converted into the
equivalent value of real type before being stored in the
variable.
Reading From Non-Text Files
If the read procedure reads values from a non-text file (i.e. a file associated
with a file variable that is not of
type text) then the type
of the values read from the file is the same as the type of
the variables used to store the values, and this
type is usually the same as the
file type's component type. The values are read from the
file and stored in the variables without conversion.
Example
read(f, x, y, z) reads three values from the file associated
with "f" into "x", "y", and "z".
Portability
Operating Systems: All
Standard Pascal: Yes
Standard Pascal does not support reading from text files into
variable of string type.
Contents | Prev | Next