I'm working on a porgram for the school works. I wrote the procedure below to save the array of records(directory) into the file. But the procedure won't work when there is a record in the file.It's urgent. Thanks for your help.

procedure saving(input : array of directory);
  var
    i : integer;
    textFile : file of directory;

  begin
    assign(textFile , 'data.dat');
	rewrite(textFile);
	for i:= 1 to 2500 do
	  write(textFile, input[i]);
	close(textFile);
  end;
program something;
uses crt;

type directory = record
                       line:string[1];
                 end;
     a = array[1..2500]of directory;

procedure saving(input:a);
var i:integer;
    f:file of directory;
begin
    assign(f,'c:\input.dat');
    {$I-}
    rewrite(f);
    {$I+}
    if ioresult = 0 then begin
       for i:=1 to 2500 do begin
           write(f,input[i]);
       end;
       close(f);
    end else writeln('error when writting to the file');
end;

var one:a;
    k:integer;

begin
    clrscr;
    {first fill the variable one}

    {example}
    for k:=1 to 2500 do begin
        one[k].line:=chr(random(255)+26);
    end;

    {and then call saving here}
    saving(one);

    readln;

end.
(*by FlamingClaw 2010.02.08*)

Thanks for your reply. I copy the above code into my program bu it still doesn't work. It just terminates after running the procedure.

of course,we call our saving procedure only once in our program,but it is writes 2500 chars to the file...

What I meant is that I've copied the code in my own program.Everything went on as usual but once the procedure is called , it just terminates. But anyway, the problem has been solved . Thanks.

by the way,I'm programming pascal during windows 7,and i needed associate the .dat to notepad or something same program to read it contents,so my above program working well...

This question has already been answered. Start a new discussion instead.