This is my program.But I got 'Crash(ACCESS_VIOLATION).Help!
Posted by
Lin 9 Jul 2001 04:58
Const Num : Array['0'..'9'] of Integer
= (0,1,2,3,4,5,6,7,8,9);
Var S : String;
P : Integer;
A : Array[300..1700] of Byte;
C : String[1];
D : Integer;
Total : Integer;
Function ReadNum : Boolean;
Var i : Integer;
Begin
i := Total;
While (S[1] in ['0'..'9']) and (S<>'') do
Begin
Inc(Total);
A[Total] := Num[S[1]];
Delete(S,1,1);
End;
If Total>i then ReadNum := True
else ReadNum := False;
End;
Function ReadE : Integer;
Var i,j : Integer;
E : Integer;
Begin
ReadE := -1;
If Not(S[1] in ['E','e']) then Exit;
Delete(S,1,1);
j := 1;
If S[1] in ['+','-'] then
Begin
If S[1]='-' then j := -1;
Delete(S,1,1);
End;
E := 0;
For i := 1 to Length(S) do
If Not(S[i] in ['0'..'9']) then Exit
else Begin
E := E*10+Num[S[i]];
If E>500 then
E := 500;
End;
ReadE := E*j;
End;
Procedure Print;
Var i,j : Integer;
Yes : Boolean;
Begin
Inc(A[D+P+1],5); j := 0;
For i := D+P+1 downto 1 do
Begin
j := j+A[i];
A[i] := j Mod 10;
j := j Div 10;
End;
For i := 1 to D do
If A[i]<>0 then Break;
Yes := False;
For j := i to D+P do
If A[j]<>0 then Yes := True;
If Yes then Write(C);
For j := i to D do
Write(A[j]);
If P>0 then
Write('.');
For j := D+1 to D+P do
Write(A[j]);
Writeln;
End;
Function Pass : Boolean;
Var i,j : Integer;
Begin
Pass := False;
If S[1]<>'.' then
Begin
If Not ReadNum then Exit;
End;
D := Total;
If S[1]='.' then
Begin
Delete(S,1,1);
If Not ReadNum then Exit;
End;
If S='' then print
else Begin
i := ReadE;
If i=-1 then exit;
D := D+i;
Print;
End;
Pass := True;
End;
Procedure Make;
Begin
Fillchar(A,Sizeof(A),0);
C := '';
If S[1] in ['+','-'] then
Begin
If S[1]='-' then C := '-';
Delete(S,1,1);
End;
Total := 1000;
If Not Pass then
Writeln('Not a floating point number');
End;
Procedure Main;
Begin
Repeat
Readln(S);
If S[1]<>'#' then
Begin
Readln(P);
Make;
End;
Until S[1]='#';
Repeat
Readln(S);
Until Eof;
End;
Begin
Main;
End.