From: brett <user@compgroups.net/>
Subject: Re: confusion with string initialization
Date: Sat, 17 Apr 2010 21:13:44 -0500
Date: 2010-04-17T21:13:44-05:00 [thread overview]
Message-ID: <HcCdnUYotp1F91fWnZ2dnUVZ_gmdnZ2d@giganews.com> (raw)
In-Reply-To: ZpWdnRumIodDKFTWnZ2dnUVZ_tudnZ2d@giganews.com
Thank you all for your very useful information, Thomas Locke's full example
of Barnes code was extremely helpful. Which I dropped into GNAT for testing.
I was having problems resolving the what? packages I needed to be able to process bounded strings, I'd already sucessfully written a Unbounded strings program and could not see why Bounded strings were causing me so many problems !
The need for "Generic_Bounded_Length" part was very unclear, and hoe it related to the rest of my code.
BTW: John Barnes Ada 2005 Book is truly excellent, however I think I also need a more "Practical Ada 2005 Programming" book as well. The titles I see on Internet book sellers are mainly Ada95 and I'm unsure if they have any relevance to learning Ada 2005. Any Suggestions ??
My finished test program is :
-- brett hallett : 18/10/2010
-- testing --redefined Integer type Temp_Int
--Bounded String type
with Ada.Strings.Bounded; use Ada.Strings.Bounded;
with Ada.Text_IO.Bounded_IO;
procedure calctemp4 is
use Ada.Strings.Bounded;
use Ada.Text_IO;
subtype Temp_Int is integer range 50 .. 350 ;
package BS is new Generic_Bounded_Length(30); use BS;
-- define the 'base' string to work with
package BS_IO is new Bounded_IO ( BS ); use BS_IO;
strline : BS.Bounded_String := (BS.Max_Length * " ");
-- create & initialize strline to spaces
C : Temp_Int := Temp_Int'First; -- start temperature
F : Integer;
function convert ( X : Integer ) return Integer is
F : Integer;
begin
F := (( X * 9 )/ 5 ) +32; -- standard C to F calc
return F;
end convert;
begin
put_line("calctemp");
put(" Celsius Farhenheit"); new_line;
while C < Temp_Int'Last loop -- loop in range
BS.overwrite(strline, 1, c'img);
f := convert(c);
BS.overwrite(strLine, 10, f'img);
BS_IO.Put_line(strline);
C := C + 25;
strline := BS.Max_Length * "*";
-- 'clear' strline ( not necessary , just testing :-)
end loop;
put(" -- finished--"); new_line;
end calctemp4;
---
frmsrcurl: http://compgroups.net/comp.lang.ada/confusion-with-string-initialization
next prev parent reply other threads:[~2010-04-18 2:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-17 13:21 confusion with string initialization brett
2010-04-17 13:06 ` Georg Bauhaus
2010-04-17 17:42 `
2010-04-17 19:01 ` J-P. Rosen
2010-04-17 21:30 ` Jeffrey R. Carter
2010-04-18 2:13 ` brett [this message]
2010-04-18 13:36 ` Alex Mentis
2010-04-19 14:54 ` Colin Paul Gloster
2010-04-19 14:12 ` J-P. Rosen
2010-04-19 18:20 ` John B. Matthews
2010-04-19 23:18 ` Adam Beneschan
2010-04-20 3:37 ` John B. Matthews
2010-04-27 9:08 ` Jacob Sparre Andersen
2010-04-28 13:26 ` BrianG
2010-04-19 19:48 `
2010-04-19 20:05 ` Warren
2010-04-19 20:06 ` Georg Bauhaus
2010-04-21 1:12 ` brett
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox