-- CS 1621 Fall 2005 -- Strings in Ada with TEXT_IO; use TEXT_IO; procedure astrings is package int_io is new integer_io(integer); use int_io; procedure backward(S: String) is -- note only one param is needed begin for i in reverse S'range loop -- Strings in Ada have attributes put(S(i)); -- the provide the range, length end loop; -- and other things. They are new_line; -- almost, but not quite, objects end backward; S1: String(1..10) := (1..10 => ASCII.NUL); -- can initialize in decl name_l, dummy: integer; begin put("Enter "); put(S1'length,1); put(" characters: "); get_line(S1, dummy); put("How long is your name? "); get(name_l); skip_line; declare S2: String(1..name_l) := (1..name_l => ASCII.NUL); -- String S2 has a different physical length than S1, but -- both can be passed to the same procedure, where name -- equivalence is required for the parameter -- However, the size is fixed once created. Clearly, this -- is somewhat restrictive and inconvenient. begin put("Enter your name: "); get_line(S2, dummy); put(S1); put(" backward is "); backward(S1); put(S2); put(" backward is "); backward(S2); end; end astrings;