comp.lang.ada
 help / color / mirror / Atom feed
From: Marin David Condic <condicma@pwfl.com>
To: Graeme Wallace <Dizzy@interact.net.au>
Subject: Re: newbie problem
Date: 1998/12/04
Date: 1998-12-04T00:00:00+00:00	[thread overview]
Message-ID: <36680053.73036E4D@pwfl.com> (raw)
In-Reply-To: 3667EE11.6E94BA0F@interact.net.au

Graeme Wallace wrote:
> 
> If I want to get user input for my program in the form of a  string of
> undefined length, how do I do so ?  If I set the string length to, say:
> 
> help_me_please : String(1..20);
> 
> I seem to be stuck with a string exactly that size.  What is the
> variable assignment which allows the actual length of the user input to
> determine the length of the string which the io system
> (ada.text_io.)gets ?
> 
> G Wallace
> 
> Thankyou.
> :-)

Ada.Text_IO does not have a Get or Get_Line procedure for variable
length strings. You have to declare a string of some sufficiently large
size to contain whatever you expect for input. (I usually use 256 bytes,
figuring that it is more than generous)

You should notice that the Get_Line procedure has a parameter "Last"
which indicates the index of the last character read. You can make use
of this in constructing variable length strings.

See the following package specs:

Ada.Strings    (ARM A.4.1)
Ada.Strings.Fixed    (ARM A.4.3)
Ada.Strings.Bounded    (ARM A.4.4)
Ada.Strings.Unbounded    (ARM A.4.5)

Between all of these - and a few related packages - you should find all
of the string handling features you need. The .Fixed package gives you
routines for handling the kinds of strings that Text_IO is going to give
you while .Bounded and .Unbounded will give you a choice of dynamically
sized strings & routines for handling them once you have read them in
via Text_IO.

I think a useful extension to the language would be variations on
Text_IO which used Bounded and Unbounded strings. But for now its just
Fixed.

MDC

-- 
Marin D. Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669

"The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man."

        --  G.B. Shaw




  parent reply	other threads:[~1998-12-04  0:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-05  0:00 newbie problem Graeme Wallace
1998-12-04  0:00 ` Mats Weber
1998-12-05  0:00   ` Matthew Heaney
1998-12-04  0:00 ` David Botton
1998-12-04  0:00 ` Gautier.DeMontmollin
1998-12-04  0:00 ` Marin David Condic [this message]
1998-12-04  0:00 ` Simon Bracken
1998-12-04  0:00   ` Marin David Condic
1998-12-05  0:00 ` Matthew Heaney
1998-12-07  0:00 ` Jeff Carter
  -- strict thread matches above, loose matches on Subject: below --
2009-05-13 14:16 Olivier Scalbert
2009-05-13 14:54 ` Martin
2009-05-13 15:20   ` Olivier Scalbert
2009-05-13 15:14 ` Adam Beneschan
2009-05-13 15:54   ` Olivier Scalbert
2009-05-13 15:44 ` Ludovic Brenta
2009-05-13 16:03   ` Olivier Scalbert
2009-05-13 18:00 ` Olivier Scalbert
2009-05-13 18:51   ` Martin
2009-05-13 19:45     ` sjw
2009-05-13 19:48     ` Olivier Scalbert
2009-05-14 19:41       ` sjw
2009-05-15  5:02         ` Olivier Scalbert
2009-05-15  8:05         ` Jean-Pierre Rosen
2009-05-18 10:23         ` Olivier Scalbert
2009-05-18 10:48           ` Martin
2009-05-18 10:54             ` Olivier Scalbert
2009-05-18 10:52           ` Ludovic Brenta
2009-05-18 11:09             ` Olivier Scalbert
2009-05-14 22:39       ` Jeffrey R. Carter
2009-05-14  2:59 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox