主题:[讨论]FPC怎么这么奇怪呀???
帮我看看这个程序:
program WnPf_741(input,output);
const fn='lottery';
var
i,min,max,code:integer;
p,m,n:string;
c:char;
function compare(fn1,fn2:string):boolean;
var
f1,f2:text;
p1,p2:string;
flag:boolean;
begin
assign(f1,fn1);reset(f1);
assign(f2,fn2);reset(f2);
flag:=true;
while (not eof(f1)) and (not eof(f2)) do begin
readln(f1,p1);
readln(f2,p2);
if p1<>p2 then begin
flag:=false;
break;
end;
end;
if (not eof(f1)) or (not eof(f2)) then flag:=false;
close(f1);close(f2);
compare:=flag;
end;
{
procedure filecopy(fn1,fn2:string);
var
f1,f2:text;
c:char;
begin
assign(f1,fn1);reset(f1);
assign(f2,fn2);rewrite(f2);
while not eof(f1) do begin
while not eoln(f1) do begin
read(f1,c);
write(f2,c);
end;
readln;
writeln;
end;
close(f1);close(f2);
end;
}
begin
assign(input,fn+'.bat');reset(input);
while not eof do begin
readln(p);
if copy(p,1,12)='for %%i in (' then break;
end;
close(input);
p:=copy(p,13,length(p)-12);
p:=copy(p,1,length(p)-16);
m:='';n:='';
i:=1;
while p[i]<>' ' do begin
n:=n+p[i];
i:=i+1;
end;
val(n,min,code);
i:=length(p);
while p[i]<>' ' do begin
m:=p[i]+m;
i:=i-1;
end;
val(m,max,code);
for i:=min to max do begin
str(i,p);
if compare(fn+'.in',fn+p+'.in') then break;
end;
assign(input,fn+p+'.out');reset(input);
assign(output,fn+'.out');rewrite(output);
while not eof do begin
while not eoln do begin
read(c);
write(c);
end;
readln;
writeln;
end;
// filecopy(fn+p+'.out',fn+'.out');
end.
这个程序在FPC里用F8单步执行,最后弹出“exitcode=0”,但输出结果是对的;但用Ctrl+F9直接执行,最后就弹出“exitcode=1”,且输出文件里没有结果。。。这是为什么?
P.S.大家可以先不用管出程序外的一些因素,文件确定没有问题,可以读取。
再P.S.我用的是Free Pascal 2.2.4。。。
program WnPf_741(input,output);
const fn='lottery';
var
i,min,max,code:integer;
p,m,n:string;
c:char;
function compare(fn1,fn2:string):boolean;
var
f1,f2:text;
p1,p2:string;
flag:boolean;
begin
assign(f1,fn1);reset(f1);
assign(f2,fn2);reset(f2);
flag:=true;
while (not eof(f1)) and (not eof(f2)) do begin
readln(f1,p1);
readln(f2,p2);
if p1<>p2 then begin
flag:=false;
break;
end;
end;
if (not eof(f1)) or (not eof(f2)) then flag:=false;
close(f1);close(f2);
compare:=flag;
end;
{
procedure filecopy(fn1,fn2:string);
var
f1,f2:text;
c:char;
begin
assign(f1,fn1);reset(f1);
assign(f2,fn2);rewrite(f2);
while not eof(f1) do begin
while not eoln(f1) do begin
read(f1,c);
write(f2,c);
end;
readln;
writeln;
end;
close(f1);close(f2);
end;
}
begin
assign(input,fn+'.bat');reset(input);
while not eof do begin
readln(p);
if copy(p,1,12)='for %%i in (' then break;
end;
close(input);
p:=copy(p,13,length(p)-12);
p:=copy(p,1,length(p)-16);
m:='';n:='';
i:=1;
while p[i]<>' ' do begin
n:=n+p[i];
i:=i+1;
end;
val(n,min,code);
i:=length(p);
while p[i]<>' ' do begin
m:=p[i]+m;
i:=i-1;
end;
val(m,max,code);
for i:=min to max do begin
str(i,p);
if compare(fn+'.in',fn+p+'.in') then break;
end;
assign(input,fn+p+'.out');reset(input);
assign(output,fn+'.out');rewrite(output);
while not eof do begin
while not eoln do begin
read(c);
write(c);
end;
readln;
writeln;
end;
// filecopy(fn+p+'.out',fn+'.out');
end.
这个程序在FPC里用F8单步执行,最后弹出“exitcode=0”,但输出结果是对的;但用Ctrl+F9直接执行,最后就弹出“exitcode=1”,且输出文件里没有结果。。。这是为什么?
P.S.大家可以先不用管出程序外的一些因素,文件确定没有问题,可以读取。
再P.S.我用的是Free Pascal 2.2.4。。。