Re: How do I point a file to stdin or stdout ?
- From: Waldek Hebisch <hebisch@xxxxxxxxxxxxxxxx>
- Date: Thu, 3 Nov 2005 21:36:57 +0000 (UTC)
Aaron Gray <ang.usenet@xxxxxxxxx> wrote:
> > This is gcc ?
>
> Yes GFC.
>
I guess you mean GPC
> > Why can't you use the standard "input" and "output" files ?
>
> I cannot seem to assign a Text file variable used to indirect file IO to a
> file or standard io.
>
> e.g.
>
> var InFile : Text;
>
> assign( InFile, 'test.txt');
>
> // use InFile
>
> InFile := Input; // This does not work
>
> // use InFile
>
> If there is no way to get round this then I will have to use an if statement
> and duplicate the code.
>
Assignment to file variables is illegal in Pascal. But you can use pointers
to files:
program inp(input, output);
var ifp : ^text;
s : string(2000);
begin
new(ifp);
{$I-} reset(ifp^, 'foo.txt'); {$I+}
if not (IOResult = 0) then begin
writeln('Can not open foo.txt');
halt;
end;
readln(ifp^, s);
writeln(s);
dispose(ifp);
ifp := @input;
readln(ifp^, s);
writeln(s);
end
..
The above is non-standard. Unfortunatly, it seems that EP way of
doing this does not work with GPC.
--
Waldek Hebisch
hebisch@xxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: How do I point a file to stdin or stdout ?
- From: Aaron Gray
- Re: How do I point a file to stdin or stdout ?
- References:
- How do I point a file to stdin or stdout ?
- From: Aaron Gray
- Re: How do I point a file to stdin or stdout ?
- From: Aaron Gray
- Re: How do I point a file to stdin or stdout ?
- From: Scott Moore
- Re: How do I point a file to stdin or stdout ?
- From: Aaron Gray
- How do I point a file to stdin or stdout ?
- Prev by Date: Re: How do I point a file to stdin or stdout ?
- Next by Date: Re: How do I point a file to stdin or stdout ?
- Previous by thread: Re: How do I point a file to stdin or stdout ?
- Next by thread: Re: How do I point a file to stdin or stdout ?
- Index(es):