READ - read input from file.
Usage:
var
f : file of TYPE;
v : TYPE;
...
read(f,v);
Where:
- f
- is a file variable that has been opened for reading using
"reset", "openf", or some other
means. If this argument is omitted, the default input
unit "input" is assumed.
- v
- is a variable whose type matches the type of the elements
in the file "f".
Description:
The "read" procedure reads a single element from the
file "f" and stores the value of that element in the
variable "v". It is equivalent to
v := f^;
get(f);
A call of the form
read(f,v1,v2,v3,...,vN);
is equivalent to
read(f,v1);
read(f,v2);
...
read(f,vN);
Special processing is available if "f" is declared
with the type "text". In this case, the variable
"v" may have several different types.
- If "v" has the type "char", a single
character is placed in "v" from the
"text" file.
- If "v" has the type "integer" (or
some integer subrange), the "read" procedure
will skip through blanks, tabs, and new-line characters
until it finds a digit or a sign (+ or -). It will then
gather digits until it finds a character that cannot be
part of an integer constant. The integer that is gathered
in this way will be assigned to the variable
"v". (If the first non-blank character that
"read" finds is NOT valid in an integer,
"read" will issue an error message.)
- If "v" has the type "real", the
"read" procedure skips white space characters
and gathers a real constant in much the same way that it
gathers an integer.
- If "v" has the type "packed array [1..N]
of char", "read" will assign input
characters to the array elements beginning with number 1.
It stops when it fills the array or when it reaches a
new-line character in the input, whichever comes first.
See Also:
expl pascal lib readln
expl pascal lib get
Copyright © 1996, Thinkage Ltd.