I tested the problem on Delphi 2009 console applications. Code like this
var F: Text; A: array[0..99] of Integer; I, J: Integer; begin Assign(F, 'test.txt'); Reset(F); I:= -1; while not EOF(F) do begin Inc(I); Read(F, A[I]); end; for J:= 0 to I do write(A[J], ' '); Close(F); writeln; readln; end.
works exactly the same as you wrote. It can be improved with the SeekEOLN function, which skips all whitespace characters; The following code does not cause an incorrect extra zero:
var F: Text; A: array[0..99] of Integer; I, J: Integer; begin Assign(F, 'test.txt'); Reset(F); I:= -1; while not EOF(F) do begin if not SeekEOLN(F) then begin Inc(I); Read(F, A[I]); end else Readln(F); end; for J:= 0 to I do write(A[J], ' '); Close(F); writeln; readln; end.
Since all these employees are just a legacy at Delphi, I think he should work at Turbo Pascal.
kludg source share