filetextnotepad++pascal

Saving text file from code


I have made this code:

Program Pzim ;
   var
     i:integer;
     vect:array[1..1001] of integer;
Begin
     i:=1;
     for i:= 1 to 999 do
     vect[i]:=i+1;
     for i:= 1 to 999 do
     writeln (vect[i]);
   readln;
End.

The program print a number sequence. I want to save in a text file what is printed.

it could be made using the Pascal yet or even using another source? Notepad++ maybe?


Solution

  • Of course you can write to a text file in Pascal.

    Program Pascal ;
    
    var
      i:integer;
      vect:array[1..1001] of integer;
      Myfile: text;
    
    begin
      i:=1;
      for i:= 1 to 999 do
        vect[i]:=i+1;
    
      Assign(Myfile, 'Myfile.txt');
      Rewrite(MyFile);
    
      for i:= 1 to 999 do
      begin
        WriteLn (vect[i]);
        WriteLn(Myfile, vect[i]);
      end;
      Close(Myfile);
      ReadLn;
    end.