Differences

This shows you the differences between two versions of the page.

Link to this comparison view

vectors.iterate [2012/01/23 22:02] (current)
thomaslocke created
Line 1: Line 1:
 +<code ada>
 +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;​
 + 
 +   ​procedure Reverse_Quote (A_Cursor : Cursor) is
 +      Org_Quote : constant Unbounded_String := Element (Position => A_Cursor);
 +      New_Backwards_Quote : Unbounded_String;​
 +   begin
 +      for i in reverse 1 .. Length (Source => Org_Quote) loop
 +         ​Append (Source ​  => New_Backwards_Quote,​
 +                 ​New_Item => Element (Source => Org_Quote,
 +                                      Index  => i));
 +      end loop;
 +      SUIO.Put_Line (Item => New_Backwards_Quote);​
 +   end Reverse_Quote;​
 +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);
 + 
 +   ​Quotes.Iterate (Process ​  => Reverse_Quote'​Access);​
 +end Quotes;
 +</​code>​
 +
 +[[Ada.Containers.Vectors#​Vectors.Iterate | Go back]]
  

Navigation