with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
with Ada.Containers.Vectors;     use Ada.Containers;
 
procedure Quotes is
   package IO renames Ada.Text_IO;
   package SUIO renames Ada.Text_IO.Unbounded_IO;
   package Quote_Container is new Vectors (Natural, Unbounded_String);
   use Quote_Container;
   Quotes    : Vector;
   Input     : IO.File_Type;
 
   --  This is the "callback" procedure
   procedure Add_42 (Element : Unbounded_String) is
   begin
      SUIO.Put_Line (Item => Element & To_Unbounded_String (" 42"));
   end Add_42;
   Q_Cursor  : Cursor;  --  Declare the cursor.
begin
   IO.Open (File => Input,
            Mode => IO.In_File,
            Name => "quotes.txt");
   while not IO.End_Of_File (File => Input) loop
      Quotes.Append (New_Item => SUIO.Get_Line (File => Input));
   end loop;
   IO.Close (Input);
 
   --  Output the first index
   Quotes.Query_Element (Index   => 0,
                         Process => Add_42'Access);
 
   --  Point the cursor at index 7 of the vector and output the element
   Q_Cursor := Quotes.To_Cursor (Index => 7);
   Query_Element (Position => Q_Cursor, Process  => Add_42'Access);
end Quotes;

Go back


Navigation