[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
files External Collections of Data Data Structure
Pascal allows you to define files--that is, external collections of
data. Three types of files are allowed: text files, data files, and
untyped files.
Text files are declared as follows:
type
<tname> = text;
var
<vname> : text;
Text files are are accessed using Read, Readln, Write, and Writeln.
All information in text files is stored as ASCII characters.
Conversion to and from Integer and Real types is automatic.
Text files consist of lines terminated by an end-of-line marker
(CR/LF). Text files end with an end-of-file marker (^Z). They can
only be processed sequentially, and simultaneous input and output is
not allowed.
Data files are declared as follows:
type
<tname> = file of <basetype>;
var
<vname> = file of <basetype>;
where <basetype> is any data type or data structure except for a file
type. Data files are accessed using Read and Write; data is kept in
binary form at all times. Seek can also be used for random access of
elements.
Untyped files are allowed by Turbo Pascal and are declared as follows:
type
<tname> = file;
var
<vname> : file;
Untyped files are accessed using BlockRead and BlockWrite, which allow
transfers of large chunks in a single statement. Seek can also be used
for random access of blocks.
-------------------------------- Example ---------------------------------
type
MyRec = record;
Cnt : Integer;
List : array[1..10] of Char;
Flag : Boolean;
Num : Real
end;
var
Iota : text; { Iota is text file variable }
Able : file of MyRec; { Able is data file variable }
Fred : file; { Fred is untyped file var }
See Also:
text
file
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson