HP Pascal/iX Programmer's Guide (31502-90023)
3- 4
Textfiles
A
textfile
is a logical file that is subdivided into lines, each of which
ends with an end-of-line marker. The components of a textfile are of
type
char
, but a textfile declaration specifies the type
text
, not FILE
OF
char
.
The standard files
input
and
output
are textfiles. If you declare them
in the program header, they are the default file parameters for all of
the sequential input and output procedures, respectively.
Example
PROGRAM prog (input,output);
VAR
tfile : text;
c : char;
BEGIN
.
.
.
read(tfile, c); {Reads from tfile}
read(c); {Reads from input}
write(c); {Writes to output}
END.
The preceding program has three textfiles: the standard textfiles input
and output, and the file tfile.
End-of-line markers are not file components, and are not of type char.
The predefined procedure
writeln
writes them to the file (see "Textfile
Input/Output" ). An end-of-line marker always precedes the
end-of-file mark in a textfile, whether
writeln
wrote the last component
to the file or not.
Current Position Indexes
Every logical file has a
current position index
that indicates either its
current component, an end-of-file marker, or (in a textfile) an
end-of-line marker. This index is an integer--the ordinal number of the
current component or marker. A file's
current component
is the component
that the next I/O operation on that file will input or output.
Figure 3-3 illustrates the relationship between
current position
index
and
current component.
Figure 3-3. Relationship Between Current
Position Index and Current Component