comp.lang.ada
 help / color / mirror / Atom feed
From: "tr4ck" <tr4ck@rediffmail.com>
Subject: Constraint error help..
Date: Mon, 20 May 2002 23:09:37 GMT
Date: 2002-05-20T23:09:37+00:00	[thread overview]
Message-ID: <RmfG8.110068$xS2.8626103@news1.calgary.shaw.ca> (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;









             reply	other threads:[~2002-05-20 23:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-20 23:09 tr4ck [this message]
2002-05-21  0:54 ` Constraint error help tmoran
2002-05-21  1:10   ` tr4ck
2002-05-21 19:05     ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox