Ada - getting string from text file and store in array -


hi im wondering how put data in array if loop txt , store in a_composite name.

procedure main        type an_array array (natural range <>) of a_composite;        type a_composite           record              name  : unbounded_string;           end record;         file       : ada.text_io.file_type;        line_count : integer := 0;       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               --i want store line string array. don't know how                  end;        end loop;        ada.text_io.close (file); end main; 

ok, have unconstrained array here. has implications; see unconstrained array gains definite length when object (general sense, not oop) declared or initialized.

as example, let's @ strings (which are unconstrained arrays of characters) example see how works:

-- create string of 10 asterisks; initialization takes bounds. : constant string(1..10):= (others => '*');  -- create string of 10 asterisks; determined initialization value. b : constant string := (1..10 => '*');  -- way of declaring string of 10 asterisks. c : constant string := ('*','*','*','*','*','*','*','*','*','*'); 

now, can these bounds function call; means can use function-calls return these values recursively.

function get_text return an_array   package unbounded renames ada.strings.unbounded;   -- you'll want get_line takes file.   function get_line return unbounded.unbounded_string     renames unbounded.text_io.get_line; begin   return (1 => (name => get_line)) & get_text; exception   when end_error => return ( 1..0 => (name => unbounded.null_unbounded_string) ); end get_text; 

so, that's how you'd using unconstrained array.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -