HELP !_(re)
Thu, 2 Nov 1995 09:14:13 -0500 (EST)
On Thu, 2 Nov 1995, Mauro Ottaviani wrote:
> Hello,
> I have a problem using files with gpc:
> In Turbo Pascal I usually use the following:
> var
> f:text;
> begin
> assign(f,'filename');
> reset(f);
> ...
> close(f);
> But this doesn't work with gpc !!
> I tryed:
> reset(f,'filename');
> This time it also compiled OK, but gives a runtime error !!
> Please HELP me !
In ISO Pascal, you have to specify any external files accessed by
your program in the Program header. For example:
Program Demo1 (InFile, OutFile);
Var
InFile, OutFile : Text;
Begin
Reset (InFile);
Rewrite (OutFile);
End {Demo1}.
'Tho ISO Pascal has no provisions for specifying a filename for the
external files, most Pascal implementations allow you to do so via the
Reset/Rewrite commands. GPC is one of these Pascal implementations. So,
modifying the above program to open the files "INDATA" for input and
"OUTDATA" for output:
Program Demo2 (InFile, OutFile);
Var
InFile, OutFile : Text;
Begin
Reset (InFile, './INDATA');
Rewrite (OutFile, './OUTDATA');
End {Demo2}.
In ISO Pascal, files are automatically closed when the program
terminates, therefore there is no "Close" command. Some Pascal
implementations, like Borland, do have a "Close" command. I don't know
if GPC has one or not.
Also, the files "Input" and "Output" are special files used for standard
input and standard output respectivly. So to use Read/Readln and
Write/Writeln to get input from the keyboard and to display something on
the screen, you have to put a "Input, Output" in your program header.
A little different from Borland, I know. But actually, if you think
about it, it's a little better to specify what external files are used in
the Program header. That way you know exactly what files are gonna be
opened by just looking at the Program header. I didn't like it at first,
but now I think it's not a bad idea.
Arcadio
Arcadio Alivio Sincero (lotu@wam.umd.edu)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es