2014-01-28 25 views
0

這是我的程序,沒有編譯信息,但在運行時它退出了,任何人都可以幫我嗎?什麼似乎是錯的? 這個問題是在我創建文件t後開始的,所以也許有些東西我看不到。提前致謝。 摺疊|複製代碼exitcode = 216在我的程序中沒有編譯信息

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. 
+0

你改變了什麼「讓它創建文件」? –

+0

我不得不打印結果,這意味着數字。在程序讀入的文本中出現少於一次的變量,所以我不能避免這樣做。它有什麼問題嗎? –

+1

我們需要一個[最小,完整,可編譯示例](http://stackoverflow.com/help/mcve)。您的示例中的哪些行更改爲「使其創建文件」? –

回答

1

的問題是,你已經聲明瞭兩個動態數組(counta)。

a, count: array of Integer; 

它們都沒有在此處分配內存。

然後,您可以分配內存a,並獲得低和高索引a

setlength(a, nums); 
Small := Low(a); 
Big := High(a); 

然後,您可以遍歷count陣列,它沒有分配的內存中的索引,但(你叫SetLengtha代替):

for i := Small to Big do 
    count[i] := 0; 

訪問存儲您還沒有分配產生Runtime error 216,這是一個訪問衝突(在Delphi,如果啓用了例外,則會產生EAccessViolation)或一般保護錯誤(在FreePascal中)。