尝试运行此程序时出现错误:
引发了CONSTRAINT_ERROR:bifid.adb:55索引检查失败
我不确定这个错误来自何处或它究竟意味着什么。有问题的一行是
End_String := End_String & Get_Character(
S, Ind(Count*(length(Cipher_Text))/2), Ind(Count));
非常感谢任何帮助。我正在使用Ada 95和GNAT编译器。
function Decipher(S : Square; Cipher_Text : Ustring) return Ustring is
type IndArray is array(1..(length(Cipher_Text)*2)) of Integer;
Ind : IndArray;
Temp : Character;
Row : Integer;
Col : Integer;
Count : Integer := 1;
End_String : Ustring;
begin
Ind := (others=>0);
for I in 1..length(Cipher_Text) loop
Temp := Uppercase(Element(Cipher_Text, I));
if In_Square(S, Temp) then
Get_Coordinates(S, Temp, Row, Col);
Ind(I) := row;
Ind(I + length(Cipher_Text)) := Col;
end if;
end loop;
while Count <= length(Cipher_Text)*2 loop
End_String := End_String & Get_Character(
S, Ind(Count*(length(Cipher_Text))/2), Ind(Count));
Count := Count + 2;
end loop;
return End_String;
end Decipher;
答案 0 :(得分:1)
对于Count&gt; 4表达式
计数*(长度(Cipher_Text))/ 2
将超过IndArray的大小。所以你的程序错了。
当你将行和列值存储长度(Cipher_Text)元素分开时, 你应该也可以使用索引来解码它们 长度(Cipher_Text)+计数。
将包含Row和Col的记录用作字段将删除所有记录 摆弄索引偏移,因为你可以存储对(Row,Col) index Count。