Click here to Skip to main content
14,836,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, this is my program, there is no compiler message, but at the runtime it exits, can anyone please help me?
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.
Posted

Error 216 is a general protection fault. Probably a memory error in your case. For instance, count is declared (and used) as an array, but you never allocated memory for it.
   
Comments
Member 10538783 28-Jan-14 15:11pm
   
Oh, yes you're right, thank you very much.
CPallini 28-Jan-14 15:29pm
   
You are welcome.
Your count array has no dimensions! So assigning values to its element is a memory violation...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900