title: Ada adding items into an array
body: <p>`Hello I am working on a project where I have to sort through a text file and find the number of times a character occurs, I have everything just about done with it but I cant figure out how to add number of occurrences of each letter into an array so I can sort it.  I believe once I can add the number of occurrences into an array as it goes through the Counters(I), I can get it to sort but I don't know how to add those items into an array can anyone help?</p>
  <p><a href="https://i.stack.imgur.com/Drl8Q.png" rel="nofollow noreferrer">This is where I go through the txt file and print the results</a></p>
  <p><a href="https://i.stack.imgur.com/ad9Y7.png" rel="nofollow noreferrer">This is how i declare everything and the sorting alg I am trying to use</a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> with Ada.Strings.Maps;
   with Ada.Text_IO; use Ada.text_io;
   with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
   with Ada.Float_Text_IO; use Ada.Float_Text_IO;  -- this if for float operations needed for percentages
                                                   --
  
  procedure test is
  
     Counters: array (Character) of Integer := (others =&gt; 0); -- initialize all Counters to 0
     type Arr is array (Positive range &lt;&gt;) of Integer;
     C:        Character;
     Infile , OutFile : File_Type;
     Uppercount : Natural;
     Lowercount : Natural;
     Specialcount : Natural;
     --Occ : array :
     subtype  lower is Character range 'a'..'z'; -- lowercase letters
     subtype  upper is Character range 'A'..'Z'; -- uppercase letters
     --P : Arr := Counters;
  
     subtype Non_Negative_Float is Float range 0.0 .. Float'Last;
     Total : Non_Negative_Float;
     Total2 : Natural;
     --Counters : array_type;
  
  
     --sorting alg I am tring to use but cant get Counter(I) values to go into an array so I can sort it here
    procedure Sort (A : in out Arr) is
        Min  : Positive;
        Temp : Integer;
     begin
        for I in A'First..A'Last - 1 loop
           Min := I;
           for J in I + 1..A'Last loop
              if A (Min) &gt; A (J) then
                 Min := J;
              end if;
           end loop;
           if Min /= I then
              Temp    := A (I);
              A (I)   := A (Min);
              A (Min) := Temp;
           end if;
        end loop;
     end Sort;
  
  
  begin
     Uppercount := 0;
     Lowercount := 0;
     Specialcount := 0;
  
     Open(InFile, In_File, ".\src\Exam2data.txt");
     Create(OutFile, Out_file, ".\src\Maginsky.txt");
     while not Ada.Text_IO.End_Of_File(InFile) loop
        Ada.Text_IO.Get(InFile, C);
        if C in lower then
        Lowercount := Lowercount + 1;
     elsif C in upper then
        Uppercount := Uppercount + 1;
     else
        Specialcount := Specialcount + 1;
     end if;
        Counters(C) := Counters(C) + 1;
  
       end loop;</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> -- goes through the file and prints the letter and times is occures
     --needs to set Counters(I) values into an array as it goes through the for loop
     for I in Counters'Range loop
        if Counters(I) &gt;= 0 then
           if I in lower or I in upper then
              -- I was not able to figure out how to put the Counters(I) into another array so it can get sorted
              -- I believe that if I can put the Counter(I) values into a new array i can sort that that array and get the
              -- correct decenting order as needed but I cant figure out how to put these values into an array for sorting
             --Sort(Counters(I));
              Ada.Text_IO.Put_Line("'" &amp; I &amp; "':" &amp; Integer'Image(Counters(I)) &amp; " Times");
              Ada.Text_IO.Put_Line(OutFile, "'" &amp; I &amp; "':" &amp; Integer'Image(Counters(I)) &amp; " Times");
  
           end if;
        end if;
     end loop;</code></pre>
  </div>
  </div>
  </p>