* Constraint error help..
@ 2002-05-20 23:09 tr4ck
2002-05-21 0:54 ` tmoran
0 siblings, 1 reply; 4+ messages in thread
From: tr4ck @ 2002-05-20 23:09 UTC (permalink / raw)
I am getting a constraint error for this line Word_Array(I) := Word; and I
can't figure out why, the program compiles fine. Below is the code for the
program. The program reads in a text file, say the file has the line, This
is a test, it just reads character by character seeing if the item is
actually a character if so it puts it into a string called word. Then the
word gets put into an word_Array. This is something simple that I am
trying, so it just returns if the item is not a character or if their are
spaces. Can someone tell my why I am getting a constaint error?
Thanks.
WITH Ada.Text_IO;
WITH Ada.Characters.Handling;
WITH Ada.IO_Exceptions;
PROCEDURE FileArray IS
FileName : String(1..80);
MaxName : CONSTANT Positive := 80;
SUBTYPE NameRange IS Positive RANGE 1..MaxName;
Length : NameRange;
DataFile : Ada.Text_IO.File_Type;
Letter : Character;
Word : String(1..10);
I : Integer := 0;
Word_Array : ARRAY(1..30) OF String(1..10);
PROCEDURE OpenFile IS --Opens a file
BEGIN
LOOP
BEGIN
Ada.Text_IO.Put(Item => "Enter the name of the file > ");
Ada.Text_IO.Get_Line(Item => FileName, Last => Length);
Ada.Text_IO.Open(File => DataFile, Mode => Ada.Text_IO.In_File, Name
=> FileName(1..Length));
Ada.Text_IO.Put("File Opened");
EXIT;
EXCEPTION
WHEN Constraint_Error =>
Ada.Text_IO.Put(Item => "Constraint Error! ");
Ada.Text_IO.Skip_Line;
WHEN Ada.Text_IO.Data_Error =>
Ada.Text_IO.Put(Item => "Data Error! ");
Ada.Text_IO.Skip_Line;
WHEN Ada.Text_IO.End_Error =>
Ada.Text_IO.Put(Item => "End Error! ");
Ada.Text_IO.Skip_Line;
WHEN Ada.IO_Exceptions.Status_Error => Ada.Text_IO.Skip_Line;
WHEN Ada.IO_Exceptions.Name_Error =>
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line ("Cannot Open " & FileName(1..Length) & "!");
Ada.Text_IO.New_Line;
END;
END LOOP;
END OpenFile;
PROCEDURE Convert IS -- Changes the characters to lowercase
BEGIN
LOOP
EXIT WHEN Ada.Text_IO.End_Of_File(File => DataFile);
LOOP
EXIT WHEN Ada.Text_IO.End_Of_Line(File => DataFile);
Ada.Text_IO.Get(File => DataFile, Item => Letter);
Letter := Ada.Characters.Handling.To_Lower(Item => Letter);
END LOOP;
Ada.Text_IO.Skip_Line(File => DataFile);
END LOOP;
END Convert;
PROCEDURE CheckChar IS -- Check one item at a time to see if its a
character,
-- if it is then it puts it in the word string
BEGIN
LOOP
IF Letter IN 'a'..'z' THEN
Word(I) := Letter;
ELSE
RETURN;
END IF;
I := I + 1;
END LOOP;
END CheckChar;
PROCEDURE Store IS -- Puts the words in the word_array
BEGIN
I := 0;
LOOP
IF I <= 30 THEN
Word_Array(I) := Word;
ELSE
RETURN;
END IF;
I := I + 1;
END LOOP;
END Store;
PROCEDURE Display IS -- Displays the contents of the word array
BEGIN
I := 1;
LOOP
Ada.Text_IO.Put(Item => Word_Array(I));
I := I + 1;
END LOOP;
END Display;
BEGIN
OpenFile;
Convert;
CheckChar;
Store;
Display;
END FileArray;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Constraint error help..
2002-05-20 23:09 Constraint error help tr4ck
@ 2002-05-21 0:54 ` tmoran
2002-05-21 1:10 ` tr4ck
0 siblings, 1 reply; 4+ messages in thread
From: tmoran @ 2002-05-21 0:54 UTC (permalink / raw)
>I am getting a constraint error for this line Word_Array(I) := Word; and I
Compiling and running with Janus Ada, I get:
** Unhandled CONSTRAINT_ERROR
Index or Subtype out of bounds - Pos of Error Value = 0
On Line Number 89 In FILEARRAY.STORE
Called from line number 115 In FILEARRAY
which is not a surprise given that the code sets I=0 and Word_Array is:
Word_Array : ARRAY(1..30) ...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-05-21 19:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-20 23:09 Constraint error help tr4ck
2002-05-21 0:54 ` tmoran
2002-05-21 1:10 ` tr4ck
2002-05-21 19:05 ` Randy Brukardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox