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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

INPUT AND OUTPUT<br />

7.9 THE PUT PROCEDURE<br />

The PUT procedure appends a new component to the end of a file.<br />

Fo rma t<br />

PUT<br />

(file va:riable);<br />

where:<br />

file variable specifies the file to which one or more<br />

components will be written.<br />

Before executing the PUT procedure, you must have executed the REWRITE<br />

procedure. REWRITE clears the file and sets EOF to TRUE, preparing<br />

the file for output. If EOF is FALSE, the PUT procedure fails; a<br />

run-time error occurs; and program execution is terminated.<br />

The PUT procedure writes the value of the file buffer variable at the<br />

end of the specified file. After execution of the PUT procedure, the<br />

value of the file buffer variable becomes undefined. EOF remains<br />

TRUE.<br />

Example<br />

PROGRAM Bookfile (INPUT,OUTPUT,Books);<br />

TYPE St T':i n~~~ :::: PACKED ARRAY [1 •• 40 J OF CHAR;<br />

Book rec ::!: RECORD<br />

Author : Strins;<br />

Title : Strins<br />

END;<br />

VAR Newbook: Bookrec;<br />

Books : FILE OF Bookrec;<br />

N : INTEGER;<br />

BEGIN<br />

END.<br />

F~EWR I TE (Books);<br />

FOR N !: 1 TO 10 DO BEGIN<br />

WITH Newbook DO BEGIN<br />

WRITE ('Title:');<br />

f~EAD (Title);<br />

WRITE ('Author!');<br />

READ (Author);<br />

END;<br />

Books- != Newbook;<br />

PUT (Book~;)<br />

END<br />

This program writes the first 10 records into the file Books. The<br />

records are input from the terminal to the record variable Newbook.<br />

They consist of two 40-character strings denoting a book's author and<br />

title. The FOR loop accepts 10 values for Newbook, assigning each new<br />

record to the file buffer variable BooksA. The PUT statement writes<br />

the value of Books A into the file for each of the 10 records input.<br />

7-15

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

Saved successfully!

Ooh no, something went wrong!