我无法从 Pascal 中的数据文件中读取多行。当我尝试读取多行时,它给了我一个“无效的数字格式”运行时错误(我只单独测试了第一行,它工作正常)。这让我觉得它与行尾的回车有关。
这是应该从我的 .DAT 文件中读取所有行的代码:
program commission;
var
moreRec:Boolean;
FileOut:Text;
FileIn:Text;
DRONE_ID:String[9];
DRONE_NAME:String[18];
SALES:Real;
COMM:Real;
procedure header;
begin
writeln(FileOut, Space(16),'SALES COMMISSION REPORT');
writeln(FileOut);
writeln(FileOut,' SSN',Space(10),'SALESPERSON',Space(9),'SALES COMMISSION');
writeln(FileOut);
end;
procedure readRec;
begin
if EOF(FileIn) THEN
moreRec:=false
else
read(FileIn, DRONE_ID);
read(FileIn, DRONE_NAME);
read(FileIn, SALES);
COMM:=SALES*0.03;
end; {readRec}
procedure initial;
begin
moreRec:=true;
Assign(FileIn, 'PRG2-150.DAT ');
Reset(FileIn);
Assign(FileOut,'output.txt');
Rewrite(FileOut);
readRec
end; {initial}
procedure process;
begin
write(FileOut, DRONE_ID);
write(FileOut, Space(2));
write(FileOut, DRONE_NAME);
write(FileOut, Space(5));
write(FileOut, SALES:9:2);
write(FileOut, Space(3));
writeln(FileOut, COMM:8:2);
readRec
end; {process}
procedure wrapup;
begin
Close(FileOut);
Close(FileIn);
end; {wrapup}
begin
initial;
header;
while moreRec = true do
process;
wrapup;
end.
这是我正在读取的 .DAT 文件:
998874673Joe Smith 27.65
849773298Sue Williams 35.90
445861253Al Oop 54.90
584988754Diane Mindykowski 25.96
758423652Alicen Morse 53.35
485236845Burton Schuring 58.52
586974512Linda Gillam 69.35
我是 Pascal 的新手,但我很想知道为什么我的程序不会读超过一行。
谢谢