31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

INPUT AND OUTPUT<br />

7.10 THE READ PROCEDURE<br />

The READ procedure reads one or more file components into a variable<br />

of the component type.<br />

Format<br />

where:<br />

READ ( [file variable,TI variable name [,variable name •.. TI);<br />

file variable<br />

variable name<br />

specifies the input file. If you omit the<br />

file variable, <strong>PASCAL</strong> uses INPUT by default.<br />

specifies the variable into which the file<br />

component(s) are read. For a text file, many<br />

file components can be read into one<br />

variable.<br />

By definition, the READ procedure<br />

assignment statement and a GET<br />

Thus, the procedure call<br />

for a nontext file performs an<br />

procedure for each variable name.<br />

READ<br />

(file variable, variable name);<br />

is equivalent to<br />

variable name := file variable~;<br />

GET (file variable);<br />

The READ procedure reads from the file until it has found a value for<br />

each variable in the list. The first value read is assigned to the<br />

first variable in the list; the second value is assigned to the<br />

second variable, and so on. The values and the variables must be of<br />

compatible types.<br />

For a text file, more than one file component (that is, more than one<br />

character) can be read into a single variable. For example, many text<br />

file components can be read into a string or numeric variable. The<br />

READ procedure repeats the assignment and GET process until it has<br />

read a sequence of characters that represent a value for the next<br />

variable in the parameter list. It continues to read components from<br />

the file until it has assigned a value to each variable in the list.<br />

Values from a text file can be read into variables of integer, real,<br />

character, string, and enumerated types. In the file, values to be<br />

read into integer and real variables must be separated by spaces or<br />

must be put on new lines. Values to be read into character variables,<br />

however, must not be separated because they are read literally,<br />

character-by-character. Constants of enumerated types must be<br />

separated by at least one space. Any other character that is invalid<br />

in an identifier terminates the constant. Only the first 31<br />

characters of the constant are significant; <strong>PASCAL</strong> ignores any<br />

remaining characters.<br />

You can use READ to read a sequence of characters from a text file<br />

into a string (that is,a variable of type PACKED ARRAY[l •• n] OF CHAR).<br />

<strong>PASCAL</strong> assigns successive characters from the file to elements of the<br />

array, in order, until each element has been assigned a value. If any<br />

characters remain on the line after the array is full, the next READ<br />

begins with the next character on that line. If the end of the line<br />

is encountered before the array is full, the remaining elements are<br />

assigned spaces.<br />

7-16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!