How to write an array to a .dat with pascal

116 views Asked by At

I need to do an assignment where I make two programs, one to write a list of players in a team and their scores, the other to read and search the .dat file for specific players.

I have chosen to do this with an array but when I run my 1st program after I enter my first players score I get an exitcode 201.

My Code:

Program TeamWrite;
    Var FName : String;
        UserFile : Text;
        Players : array[1..10] of string;
        Score : array[1..10] of integer;
        List1: Integer;
        List2: Integer;

BEGIN
  FName := 'Team';
    Assign(UserFile, 'C:\Team.dat');
    Rewrite(UserFile);
    FOR List1:= 1 to 10 DO
            begin
                Writeln('Enter players name and score separated by pressing enter.');
                Readln(Players[List1]);
                Readln(Score[List2]);
                Writeln(UserFile, Players[List1]);
                Writeln(UserFile, Score[List2]);
            end;
    close(UserFile);
End.

Please help!

1

There are 1 answers

2
ycsun On

Your variable List2 is uninitialized, so Score[List2] generates an "index out of bound" error. Actually you don't need List2 at all; just use List1 instead and your program should work.