Im having a trouble storing unbounded string to an array if I'mm getting it to .txt file. Here is my hardcoded data:
Data : An_Array := (1 => (Name => +"9 - Joe"),
2 => (Name => +"8 - Trisha "),
3 => (Name => +"7 - RR "),
4 => (Name => +"6 - Jane "),
5 => (Name => +"5 - Doe "));
What if I want to get the data from a .txt
file?
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
function "+" (S : String) return Unbounded_String renames To_Unbounded_String;
type A_Composite is
record
Name : Unbounded_String;
end record;
function "<" (L, R : A_Composite) return Boolean is
begin
return L.Name < R.Name;
end "<";
procedure Put_Line (C : A_Composite) is
begin
Put_Line (To_String (C.Name));
end Put_Line;
type An_Array is array (Natural range <>) of A_Composite;
procedure Sort is new Ada.Containers.Generic_Array_Sort (Natural, A_Composite, An_Array);
Data : An_Array := (1 => (Name => +"9 - Joe"),
2 => (Name => +"8 - Trisha "),
3 => (Name => +"7 - RR "),
4 => (Name => +"6 - Jane "),
5 => (Name => +"5 - Doe "));
begin
Ada.Text_IO.Open (File => File,
Mode => Ada.Text_IO.In_File,
Name => "highscore.txt");
while not Ada.Text_IO.End_Of_File (File) loop
declare
Line :String := Ada.Text_IO.Get_Line (File);
begin
-- get data from .txt and I want it to sotre to Data : An_Array
end;
end loop;
Ada.Text_IO.Close (File);
Sort (Data);
for I in Data'Range loop
Put_Line (Data (I));
end loop;
end Main;