Description
The reset procedure associates a file variable with a file (i.e. opens the file variable and allows it to be used to manipulate the file). The reset procedure opens the file variable in read-only mode. The open procedure can also be used to open file variables in read-only mode.
Parameters
File variables can get named in the following ways:
The program below is used to count the number of vowels and the total number of characters in the input file. If you run this program and don't supply a program argument like
ivm vowels
then the program reads from the standad input file. If you run this program with a program argument like
ivm vowels filename
then the program will open the file named filename and read from it.
program vowels(f, output);
var
f : file of char;
tot, vow : integer;
c : char;
begin
reset(f); //Open the input file in readmode.
tot := 0; //Initialize total number of chars read so far
vow := 0; //Initialize total number of vowels read so far
while not eof(f) do
begin
read(f, c); //Read character
case c of
'a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U'
: vow := vow + 1;
otherwise //include "otherwise" so that non-vowels don't cause errors.
end;
tot := tot + 1;
end;
writeln('Total characters read = ', tot);
writeln('Vowels read = ', vow)
end.
Portability
Operating Systems: All
Standard Pascal: Yes