I'm learning about using pascal to read integers from text file. The program should read and print 10 integers, but the it actually printed 11 values which it printed extra 0 in the end. I used to meet the same problem when I writing c++ program, but I solved it by using while(inFile >> num)
instead of while(!EOF{infile >> num;}
.
Here is the pascal code for my program:
program testRead;
uses crt;
var
nSize : integer;
num, sum : longint;
root : real;
f : text;
begin
assign(f, 'numbers.txt');
reset(f);
nSize := 0;
while not eof(f) do
begin
read(f, num);
writeln(num);
end;
close(f);
end.