Subsections

Summary

External values (usually called data) are stored in books. A program uses an internal structure, called a file (of mode FILE), to keep track of the process of transferring data to or from books. The link between them is controlled by a channel.

A number of procedures are provided in the standard prelude to facilitate the transfer of data to and from books, as well as changing the position recorded by a file within a book.

Books can be created and written to, or opened and read from, or both read from and written to. A file should be closed to sever the link between itself and its corresponding book, and to ensure that any data storage areas (usually called buffers) are flushed to the storage medium.

Formatting of numbers can be performed with the procedures whole, fixed and float. This facilitates the production of reports.

String terminators make it easier to read values of mode STRING. They are set with the procedure make term.

The command line can be read just like any other book (text only) and environment variables can be read.


Exercises

9.20
Write a program to read real numbers from the keyboard, and write them to the screen in scientific notation and 3 decimal places. Continue until zero is read. Ans[*]
9.21
Using the mode EMPLOYEE declared in section 7.5, write a program to read the employee records from a binary book, and write a report of the name of each employee, her or his net pay for the current week and the total net pay and number of employees read. In the binary book, each string is preceded by the length of that string as an integer. Get the book idf and the week number from the command line. Ans[*]


Sian Mountbatten 2012-01-19