comp.lang.ada
 help / color / mirror / Atom feed
* Storing A string
@ 2002-02-14 17:04 Anthony Wise
  2002-02-14 18:07 ` Marin David Condic
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Anthony Wise @ 2002-02-14 17:04 UTC (permalink / raw)


Hi
another newbie question !

I need my program to be able to accept lines of text.  These lines can be as 
long or short as the user likes.
I am using the Get_Line procedure (Using only one string), however this 
allows only one entery.  So i put Get_Line in a loop, but now the only 
accessable input is the last input.  Is there anyway i can store all the 
inputs so i can process  them and then output them all together.
all advice welcomed thx.

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Storing A string
  2002-02-14 17:04 Storing A string Anthony Wise
@ 2002-02-14 18:07 ` Marin David Condic
  2002-02-14 18:23 ` Matthew Heaney
  2002-02-15 13:05 ` Marc A. Criley
  2 siblings, 0 replies; 5+ messages in thread
From: Marin David Condic @ 2002-02-14 18:07 UTC (permalink / raw)


There must be 50 ways to do what you're describing. The important thing to
remember is that Get_Line works like assignment - it replaces the content of
the string with the new content when you read.

Take note of the fact that Get_Line has a parameter called "Last" that
indicates the last character read for the line. Also note that you can
reference a slice of a string as in: Some_String (Start_Pos..End_Pos), so
you could utilize Get_Line, Last and slices to read several times into the
same string object at different positions.

But that doesn't seem like it would entirely do what you want, because as
you may not have noticed, a String is not dynamic - it has a fixed size that
you will eventually exhaust if you keep concatenating to it in a loop.

What may be more useful is to investigate Unbounded_String. (See: ARM
Appendix A.4.5) You can take a String and concatenate to the end of an
Unbounded_String (as well as many other operations) and then the string can
keep growing until you exhaust available memory.

You'll find it really helpful when dealing with strings to look over the
predefined string handling packages that Ada provides. Check out the
appendices of the ARM or a good Ada book to find all the help Ada gives you
with this.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Anthony Wise" <iamwisey_@hotmail.com> wrote in message
news:mailman.1013706303.15083.comp.lang.ada@ada.eu.org...
> Hi
> another newbie question !
>
> I need my program to be able to accept lines of text.  These lines can be
as
> long or short as the user likes.
> I am using the Get_Line procedure (Using only one string), however this
> allows only one entery.  So i put Get_Line in a loop, but now the only
> accessable input is the last input.  Is there anyway i can store all the
> inputs so i can process  them and then output them all together.
> all advice welcomed thx.
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Storing A string
  2002-02-14 17:04 Storing A string Anthony Wise
  2002-02-14 18:07 ` Marin David Condic
@ 2002-02-14 18:23 ` Matthew Heaney
  2002-02-15 13:05 ` Marc A. Criley
  2 siblings, 0 replies; 5+ messages in thread
From: Matthew Heaney @ 2002-02-14 18:23 UTC (permalink / raw)



"Anthony Wise" <iamwisey_@hotmail.com> wrote in message
news:mailman.1013706303.15083.comp.lang.ada@ada.eu.org...
> I need my program to be able to accept lines of text.  These lines can be
as
> long or short as the user likes.
> I am using the Get_Line procedure (Using only one string), however this
> allows only one entery.  So i put Get_Line in a loop, but now the only
> accessable input is the last input.  Is there anyway i can store all the
> inputs so i can process  them and then output them all together.
> all advice welcomed thx.

You can either write a recursive version of you string query function, that
returns type String as the return value, or implement a loop and store
fixed-length strings in an Unbounded_String.







^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Storing A string
  2002-02-14 17:04 Storing A string Anthony Wise
  2002-02-14 18:07 ` Marin David Condic
  2002-02-14 18:23 ` Matthew Heaney
@ 2002-02-15 13:05 ` Marc A. Criley
  2 siblings, 0 replies; 5+ messages in thread
From: Marc A. Criley @ 2002-02-15 13:05 UTC (permalink / raw)


Anthony Wise wrote:
> 
> Hi
> another newbie question !
> 
> I need my program to be able to accept lines of text.  These lines can be as
> long or short as the user likes.
> I am using the Get_Line procedure (Using only one string), however this
> allows only one entery.  So i put Get_Line in a loop, but now the only
> accessable input is the last input.  Is there anyway i can store all the
> inputs so i can process  them and then output them all together.
> all advice welcomed thx.

After reading each string in your loop, you need to store it away
somewhere for later reference.  Arrays and lists are commonly used for
such a purpose.

Marc A. Criley
Consultant
Quadrus Corporation
www.quadruscorp.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Storing A string
       [not found] <F14ETmXuldbjZj8RfDy00001fdf@hotmail.com>
@ 2002-02-21 12:21 ` M. A. Alves
  0 siblings, 0 replies; 5+ messages in thread
From: M. A. Alves @ 2002-02-21 12:21 UTC (permalink / raw)


On Thu, 14 Feb 2002, Anthony Wise wrote:
> I need my program to be able to accept lines of text. [1] These lines
> can be as long or short as the user likes. [2] I am using the Get_Line
> procedure (Using only one string)

Note that, in rigour, [1] and [2] are incompatible, since a String has
limited length.

However we can assume a big limit = no limit in practice, and for
expository purposes of the next question.

> , however this allows only one entery.  So i put Get_Line in a loop,
> but now the only accessable input is the last input.  Is there anyway
> i can store all the inputs so i can process them and then output them
> all together.

Store where? In main memory? Sure. Since we are already in a 'limits'
idiom, I suggest an array of Unbounded_String e.g. (not tested):

  Line_Buffer : String (1 .. 1000);
  Line_Length : Natural range 0 .. Line_Buffer'Last;
  Line_Store  : array (1 .. 10_000) of Unbounded_String;
  Line_Count  : Natural range 0 .. Line_Store'Last;
begin
  loop
    Get_Line (Line_Buffer, Line_Length);
    Line_Count := Line_Count + 1;
    Line_Store (Line_Count) :=
      To_Unbounded_String (Line_Buffer (1 .. Line_Length));
    ... -- some exit condition here
  end loop;
  -- 'output them all together' (?) here

-- 
   ,
 M A R I O   data miner, LIACC, room 221   tel 351+226078830, ext 121
 A M A D O   Rua Campo Alegre, 823         fax 351+226003654
 A L V E S   P-4150-180 PORTO, Portugal    mob 351+939354002





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-02-21 12:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-14 17:04 Storing A string Anthony Wise
2002-02-14 18:07 ` Marin David Condic
2002-02-14 18:23 ` Matthew Heaney
2002-02-15 13:05 ` Marc A. Criley
     [not found] <F14ETmXuldbjZj8RfDy00001fdf@hotmail.com>
2002-02-21 12:21 ` M. A. Alves

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