High-level
Programming Language (Pascal)
Text
File
- is a collection of alphanumeric
characters
- is ended with the character
<eof> (end-of-file)
- all file_variables should
be declared at the var declaration
¡@e.g var infile, outfile
: text;
Relevant Procedures
- assign (file_variable,
'external_file')
- is used to associate
a file variable with the external file
- e.g. assign (infile,
'DataIn.txt');
- establish a link
between the file_variable (infile) and the external_file (DataIn.txt)
- reset (file_vaiable)
- to open a file for
input (reading)
- e.g reset (infile);
- to open the file
(infile) for input
- set the file
pointer to the beginning of a file
- file pointer
is a marker that points to the next character to be processed in a
file
- read (file_vaiable, input_list)
/ readln (file_vaiable, input_list)
- input_list is used
to store the data
- types of input_list
variables should be integer, real, char, string
- rewrite (file_variable)
- to open a file for
output (writing)
- e.g rewrite (outfile);
- to open the file
(outfile) for output
- set the file
pointer to the beginning of a file
- if the external
file (DataOut.txt) does not exist then an empty file (DataOut.txt)
will be created
- if the file already
exists and is not an empty file then rewrite statement will erase
all the data in the file (DataOut.txt)
- write (file_variable,
output_list) / writeln (file_variable, output_list)
- close (file_variable)
- to close the file
- force the buffer
to proceed the transfer (writing the data into the external file)
- all opened input
files and output files must be closed if they will not be reused in the
program
Relevant Function
- eof (file_variable)
- to determine whether
the character is an end-of-file character
- any attempt to read
data beyond the <eof> will cause a run-time error