[fpc-pascal]dumb question

Michael Van Canneyt michael.vancanneyt at wisa.be
Mon Aug 2 10:12:26 CEST 2004


On Sun, 1 Aug 2004 Swh8204 at aol.com wrote:

> Ok, guys.  it's only been like 15 years since I have written any pascal code.
>  Can someone please help me with syntax for opening a file so that I can read
> variable length lines of text from it, then output to another file. Running
> in DOS on an x86 machine.  Thank you.

Here you are. Standard textbook examples. Also available in the manual.

Michael.

procedure ReadFile(FN : String);

Var
  F : Text;
  S : String;

begin
  Assign(F,FN);
  Reset(F);
  While not EOF(F) do
    begin
    ReadLn(F,S);
    { Do something with S. }
    end;
  Close(F);
end;

procedure WriteFile(FN : String);

Var
  F : Text;
  I : Integer;
  S : String;

begin
  Assign(F,FN);
  Rewrite(F);
  For I:=0 to 100 do
    Writeln(F,'Writing string ',I);
  Close(F);
end;





More information about the fpc-pascal mailing list