The Ada Program: frequency.adb
1 -- frequency.adb: count, display character frequency in standard input
2
3 with Ada.Text_IO;
4 use Ada;
5
6 procedure Frequency is
7
8 subtype Printable is Character range ' ' .. '~';
9 Counts : array (Printable) of Natural := (Printable => 0);
10
11 Char: Character;
12
13 begin
14
15 while not Text_IO.End_Of_File loop
16 while not Text_IO.End_Of_Line loop
17 Text_IO.Get (Item=>Char);
18 if Char in Printable then
19 Counts (Char) := Counts (Char) + 1;
20 end if;
21 end loop;
22 Text_IO.Skip_Line; -- move pointer in input buffer past EOL
23 end loop;
24
25 for I in Counts'Range loop
26 if Counts(I) > 0 then
27 Text_IO.Put (I & ": ");
28 for J in 1 .. Counts(I) loop
29 Text_IO.Put ('*');
30 end loop;
31 Text_IO.New_Line;
32 end if;
33 end loop;
34
35 end Frequency;