Pascal exitcode=216在我的程序中,不编译消息
这是我的程序,没有编译器消息,但在运行时它退出,有人能帮我吗?怎么了? 问题是在我创建文件t之后开始的,所以可能有一些东西我看不见。提前谢谢。 折叠|复制代码Pascal exitcode=216在我的程序中,不编译消息,pascal,freepascal,Pascal,Freepascal,这是我的程序,没有编译器消息,但在运行时它退出,有人能帮我吗?怎么了? 问题是在我创建文件t之后开始的,所以可能有一些东西我看不见。提前谢谢。 折叠|复制代码 program MyProgr; var F: text; t: Textfile; a, count: array of Integer; b: Integer; i, int: Integer; countnums: Integer; n, m: String; lin, nums: Integer;
program MyProgr;
var
F: text;
t: Textfile;
a, count: array of Integer;
b: Integer;
i, int: Integer;
countnums: Integer;
n, m: String;
lin, nums: Integer;
Small, Big: Integer;
procedure DoWhatEver(S: string);
begin
val(S, int);
Write(S, ' ');
for i := Small to Big do
if (a[i] = int) then
count[i] := count[i] + 1;
end;
procedure FilltheArray;
begin
for i := Small to Big do
a[i] := i + 1;
end;
procedure ProcessString;
var
Strng, S: string;
Last, P: Integer;
begin
readln(F, Strng);
Last := 0;
while Last < length(Strng) do
begin
P := Last + 1;
while (P <= length(Strng)) and (Strng[P] <> ' ') do
inc(P);
S := copy(Strng, Last + 1, (P - Last - 1));
DoWhatEver(S);
Last := P;
end
end;
procedure ProcessStringA;
var
Strng: string;
Last, P: Integer;
begin
readln(F, Strng);
Last := 0;
while Last < length(Strng) do
begin
P := Last + 1;
while (P <= length(Strng)) and (Strng[P] <> ' ') do
inc(P);
n := copy(Strng, Last + 1, (P - Last - 1));
val(n, nums);
Last := P;
end
end;
procedure ProcessStringB;
var
Strng: string;
Last, P: Integer;
begin
readln(F, Strng);
Last := 0;
while Last < length(Strng) do
begin
P := Last + 1;
while (P <= length(Strng)) and (Strng[P] <> ' ') do
inc(P);
m := copy(Strng, Last + 1, (P - Last - 1));
val(m, lin);
Last := P;
end
end;
begin
assign(F, 'myfile.txt');
reset(F);
ProcessStringA;
Writeln(nums);
ProcessStringB;
Writeln(lin);
setlength(a, nums);
Small := Low(a);
Big := High(a);
for i := Small to Big do
count[i] := 0;
FilltheArray;
while not eof(F) do
ProcessString;
for i := Small to Big do
begin
if count[i] = 2 then
countnums := countnums + 1;
end;
Close(F);
assign(t, 'fileout.txt');
Rewrite(t);
Writeln(t, countnums);
Close(t);
end.
程序MyProgr;
变量
F:文本;
t:文本文件;
a、 count:整数数组;
b:整数;
i、 int:整数;
countnums:整数;
n、 m:字符串;
林,nums:整数;
小,大:整数;
程序DoWhatEver(S:字符串);
开始
val(S,int);
写(S,,);
对于i:=从小到大
如果(a[i]=int),那么
计数[i]:=计数[i]+1;
结束;
程序填充阵列;
开始
对于i:=从小到大
a[i]:=i+1;
结束;
过程字符串;
变量
Strng,S:字符串;
最后,P:整数;
开始
readln(F,Strng);
最后:=0;
而最后<长度(Strng)则
开始
P:=Last+1;
而(P问题是您已经声明了两个动态数组(
count
和a
)
此时它们都没有分配内存
然后为a
,并获得a的低和高索引:
setlength(a, nums);
Small := Low(a);
Big := High(a);
然后在count
数组中循环这些索引,该数组尚未分配内存(您在a
上调用了SetLength
):
访问尚未分配的内存会生成运行时错误216
,这是访问冲突(在中,如果启用了异常,则会引发eaccessinvalition
)或一般保护错误(在中)。您将什么更改为“使其创建文件”?我必须打印结果,这意味着程序读取的文本中出现不到一次的变量的数量,所以我无法避免这样做。它有什么问题吗?我们需要一个。您的示例中的哪些行更改为“make it create the file”?216似乎取消了对零指针的引用。为什么要重置(F)问题是我没有为伯爵分配备忘录,谢谢你的帮助。
setlength(a, nums);
Small := Low(a);
Big := High(a);
for i := Small to Big do
count[i] := 0;