with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
-- Read and print up to maxsize strings
-- A String is a fixed length array of characters
-- Uses an array of strings and an array of string lengths
-- Uses of get_line to read a string
procedure printnstrings is
maxsize: constant natural := 100; -- maximum number of strings
stringsize: constant natural := 80; -- maximum string size
-- Type for an array of strings
type stringarray is array(1 .. maxsize) of string(1..stringsize);
-- Type for an array of string lengths
type intarray is array(1 .. maxsize) of Natural;
-- Gets ne strings in array a, with their lengths in array la
procedure myget(a: out stringarray; la: out intarray; ne: out Natural) is
aString: string(1..stringsize);
len: Natural;
begin
ne := 0;
while not end_of_file loop
get_line(aString, len);
ne := ne + 1;
a(ne) := aString; -- Store the string
la(ne) := len; -- Store the length
end loop;
end myget;
-- Print the list of strings, last string first, forwards and backwards
procedure myput(a: in stringarray; la: intarray; ne: in Natural) is
begin
for i in 1 .. ne loop
put(a(i)(1..la(i))); -- Print a string slice
-- Print each string in reverse!
for j in reverse 1 .. la(i) loop
put(a(i)(j));
end loop;
new_line;
end loop;
end myput;
numEntered: Natural;
thearray: stringarray; -- Array for strings
lenArray: intarray; -- Array for lengths
begin
myget(thearray, lenArray, numEntered);
myput(thearray, lenArray, numEntered);
end printnstrings;