comp.lang.ada
 help / color / mirror / Atom feed
* HELP!!!!!!
@ 2001-10-17 14:34 F
  2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: F @ 2001-10-17 14:34 UTC (permalink / raw)


I would like to make a program in wich a string is given in input and the
dimension of it is unknown (till someone insert it...)
HOW CAN I DO?????? (without using hundreds of lines)
Thank you!!!!!!!!!!
Just a consideration, string's manage in Ada is not so beutifull: i can
implement a server without problems but i cannot take a string in
input...........
Bye Phosphorus





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

* Re: HELP!!!!!!
  2001-10-17 14:34 HELP!!!!!! F
@ 2001-10-17 16:10 ` Chris M. Moore
  2001-10-17 16:36   ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
                     ` (2 more replies)
  2001-10-17 16:28 ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
  2001-10-17 17:31 ` HELP!!!!!! tmoran
  2 siblings, 3 replies; 11+ messages in thread
From: Chris M. Moore @ 2001-10-17 16:10 UTC (permalink / raw)


On Wed, 17 Oct 2001 16:34:03 +0200, "F" <phosphorus@libero.it> wrote:

>I would like to make a program in wich a string is given in input and the
>dimension of it is unknown (till someone insert it...)
>HOW CAN I DO?????? (without using hundreds of lines)

function Read_String_From_Keyboard return String is
  Temp_Str : Ada.Strings.Unbounded.Unbounded_String :=
    Ada.Strings.Unbounded.Null_Unbounded_String;
  Ch : Character;
begin
  while not Ada.Text_IO.End_Of_Line loop
    Ada.Text_IO.Get(Ch);
    Temp_Str := Ada.Strings.Unbounded."&"(Temp_Str, Ch);
  end loop;
  return Ada.Strings.Unbounded.To_String(Temp_Str);
end Read_String_From_Keyboard;

seems like the safest way.  I haven't tried compiling this though so
who knows!

--
Chris M. Moore
Software engineer
speaking for myself



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

* How to read in very long strings. (was: HELP!!!!!!)
  2001-10-17 14:34 HELP!!!!!! F
  2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
@ 2001-10-17 16:28 ` Marin David Condic
  2001-10-17 22:18   ` Jeffrey Carter
  2001-10-17 17:31 ` HELP!!!!!! tmoran
  2 siblings, 1 reply; 11+ messages in thread
From: Marin David Condic @ 2001-10-17 16:28 UTC (permalink / raw)


You really shouldn't use a subject line of HELP!!!! since it is too vague to
get the proper attention.

The AdaPower web site has an example of this. Go to
http://www.adapower.com/index2.html and click on "Source Code". Follow that
to "Language and Technique Examples". Look for "Reading Long Strings Using
Recursion (Carlisle)" and you will find an answer. You will along the way
find lots of other useful stuff.

Just because I'm a Really Wonderful Guy, I'll cut-n-paste the code here for
you, but you'll still want to go to AdaPower since you will undoubtedly find
lots of additional help for problems yet to arise...

function Next_Line(File : in Ada.Text_IO.File_Type :=
   Ada.Text_Io.Standard_Input) return String is
   Answer : String(1..256);
   Last   : Natural;
begin
   Ada.Text_IO.Get_Line(File => File,
      Item => Answer,
      Last => Last);
   if Last = Answer'Last then
      return Answer & Next_Line(File);
   else
      return Answer(1..Last);
   end if;
end Next_Line;


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/

"F" <phosphorus@libero.it> wrote in message
news:9qk4lr$1tvj$1@newsreader1.mclink.it...
> I would like to make a program in wich a string is given in input and the
> dimension of it is unknown (till someone insert it...)
> HOW CAN I DO?????? (without using hundreds of lines)
> Thank you!!!!!!!!!!
> Just a consideration, string's manage in Ada is not so beutifull: i can
> implement a server without problems but i cannot take a string in
> input...........
> Bye Phosphorus
>
>





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

* Re: How to read in very long strings. (was: HELP!!!!!!)
  2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
@ 2001-10-17 16:36   ` Marin David Condic
  2001-10-17 18:17   ` HELP!!!!!! Jeffrey Carter
  2001-10-18  7:10   ` HELP!!!!!! F
  2 siblings, 0 replies; 11+ messages in thread
From: Marin David Condic @ 2001-10-17 16:36 UTC (permalink / raw)


It looks like a fair answer, but is likely to be rather slow in execution.
How slow will depend on the implementation of Unbounded_String. It could end
up doing a lot of dynamic allocation/deallocation as you append the
characters one at a time.

See my other post with a solution from AdaPower. (I'm not smart enough to
dream up something this slick! But I *am* smart enough to
steal^H^H^H^H^HReuse a good thing when I see it. :-) A really slick solution
might be to produce some version combining both the recursion and the
Unbounded_String - which I prefer to use over the plain vanilla String in
most instances.

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/


"Chris M. Moore" <chris.m.moore@amsjv.com> wrote in message
news:3bcdaa4e.11615702@news.geccs.gecm.com...
> On Wed, 17 Oct 2001 16:34:03 +0200, "F" <phosphorus@libero.it> wrote:
>
> >I would like to make a program in wich a string is given in input and the
> >dimension of it is unknown (till someone insert it...)
> >HOW CAN I DO?????? (without using hundreds of lines)
>
> function Read_String_From_Keyboard return String is
>   Temp_Str : Ada.Strings.Unbounded.Unbounded_String :=
>     Ada.Strings.Unbounded.Null_Unbounded_String;
>   Ch : Character;
> begin
>   while not Ada.Text_IO.End_Of_Line loop
>     Ada.Text_IO.Get(Ch);
>     Temp_Str := Ada.Strings.Unbounded."&"(Temp_Str, Ch);
>   end loop;
>   return Ada.Strings.Unbounded.To_String(Temp_Str);
> end Read_String_From_Keyboard;
>
> seems like the safest way.  I haven't tried compiling this though so
> who knows!
>
> --
> Chris M. Moore
> Software engineer
> speaking for myself





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

* Re: HELP!!!!!!
  2001-10-17 14:34 HELP!!!!!! F
  2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
  2001-10-17 16:28 ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
@ 2001-10-17 17:31 ` tmoran
  2 siblings, 0 replies; 11+ messages in thread
From: tmoran @ 2001-10-17 17:31 UTC (permalink / raw)


> I would like to make a program in wich a string is given in input and the
> dimension of it is unknown (till someone insert it...)
> HOW CAN I DO?????? (without using hundreds of lines)
  function Fetch_Message return String is
    -- Does one or more Get_Line's to return an arbitrarily large string.
    Message : String(1 .. 80); -- usually adequate
    Last    : Natural;
  begin
    Ada.Text_IO.Get_Line(Message, Last);
    if Last = Message'last then -- there's still more, fetch it
      return Message(Message'first .. Last) & Fetch_Message;
    end if;
    return Message(Message'first .. Last);
  end Fetch_Message;

> Just a consideration, string's manage in Ada is not so beutifull: i can
> implement a server without problems but i cannot take a string in
> input...........
  When you find something simple seems hard to do in Ada, you must be
missing something.  When you find something hard is hard to do, there's
probably a better way in Ada.



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

* Re: HELP!!!!!!
  2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
  2001-10-17 16:36   ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
@ 2001-10-17 18:17   ` Jeffrey Carter
  2001-10-18  7:10   ` HELP!!!!!! F
  2 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Carter @ 2001-10-17 18:17 UTC (permalink / raw)


"Chris M. Moore" wrote:
> 
> On Wed, 17 Oct 2001 16:34:03 +0200, "F" <phosphorus@libero.it> wrote:
> 
> >I would like to make a program in wich a string is given in input and the
> >dimension of it is unknown (till someone insert it...)
> >HOW CAN I DO?????? (without using hundreds of lines)
> 
> function Read_String_From_Keyboard return String is
>   Temp_Str : Ada.Strings.Unbounded.Unbounded_String :=
>     Ada.Strings.Unbounded.Null_Unbounded_String;
>   Ch : Character;
> begin
>   while not Ada.Text_IO.End_Of_Line loop
>     Ada.Text_IO.Get(Ch);
>     Temp_Str := Ada.Strings.Unbounded."&"(Temp_Str, Ch);
>   end loop;
>   return Ada.Strings.Unbounded.To_String(Temp_Str);
> end Read_String_From_Keyboard;
> 
> seems like the safest way.  I haven't tried compiling this though so
> who knows!

This seems like more work than is needed. PragmARC.Get_Line from the
PragmAda Reusable Components does this (and from other
Ada.Text_IO.File_Type files as well) without repeatedly modifying an
unbounded string.

-- 
Jeffrey Carter



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

* Re: How to read in very long strings. (was: HELP!!!!!!)
  2001-10-17 16:28 ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
@ 2001-10-17 22:18   ` Jeffrey Carter
  2001-10-18 13:39     ` Marin David Condic
  0 siblings, 1 reply; 11+ messages in thread
From: Jeffrey Carter @ 2001-10-17 22:18 UTC (permalink / raw)


Marin David Condic wrote:
> 
> function Next_Line(File : in Ada.Text_IO.File_Type :=
>    Ada.Text_Io.Standard_Input) return String is

Ada.Text_IO.Current_Input would be a better default for this, so it can
handle redirected input. This is the approach taken by
PragmARC.Get_Line.

-- 
Jeffrey Carter



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

* Re: HELP!!!!!!
  2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
  2001-10-17 16:36   ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
  2001-10-17 18:17   ` HELP!!!!!! Jeffrey Carter
@ 2001-10-18  7:10   ` F
  2001-10-18  8:11     ` HELP!!!!!! Martin Dowie
  2 siblings, 1 reply; 11+ messages in thread
From: F @ 2001-10-18  7:10 UTC (permalink / raw)


My problem is the second time i recall the function read string, in fact the
value of the function end_of_line remains true after the first time in wich
the user press return.....
II'm trying to use the procedure get_line instead of  get, i'll give you
news about this "experiment"
Thank you for your help
Phosphorus

Chris M. Moore ha scritto nel messaggio
<3bcdaa4e.11615702@news.geccs.gecm.com>...
>On Wed, 17 Oct 2001 16:34:03 +0200, "F" <phosphorus@libero.it> wrote:
>
>>I would like to make a program in wich a string is given in input and the
>>dimension of it is unknown (till someone insert it...)
>>HOW CAN I DO?????? (without using hundreds of lines)
>
>function Read_String_From_Keyboard return String is
>  Temp_Str : Ada.Strings.Unbounded.Unbounded_String :=
>    Ada.Strings.Unbounded.Null_Unbounded_String;
>  Ch : Character;
>begin
>  while not Ada.Text_IO.End_Of_Line loop
>    Ada.Text_IO.Get(Ch);
>    Temp_Str := Ada.Strings.Unbounded."&"(Temp_Str, Ch);
>  end loop;
>  return Ada.Strings.Unbounded.To_String(Temp_Str);
>end Read_String_From_Keyboard;
>
>seems like the safest way.  I haven't tried compiling this though so
>who knows!
>
>--
>Chris M. Moore
>Software engineer
>speaking for myself





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

* Re: HELP!!!!!!
  2001-10-18  7:10   ` HELP!!!!!! F
@ 2001-10-18  8:11     ` Martin Dowie
  2001-10-18 16:57       ` HELP!!!!!! Jeffrey Carter
  0 siblings, 1 reply; 11+ messages in thread
From: Martin Dowie @ 2001-10-18  8:11 UTC (permalink / raw)


"F" <phosphorus@libero.it> wrote in message
news:9qlv2v$25md$1@newsreader1.mclink.it...
> My problem is the second time i recall the function read string, in fact
the
> value of the function end_of_line remains true after the first time in
wich
> the user press return.....
> II'm trying to use the procedure get_line instead of  get, i'll give you
> news about this "experiment"
> Thank you for your help

Have you tried flushing the keyboard buffer?





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

* Re: How to read in very long strings. (was: HELP!!!!!!)
  2001-10-17 22:18   ` Jeffrey Carter
@ 2001-10-18 13:39     ` Marin David Condic
  0 siblings, 0 replies; 11+ messages in thread
From: Marin David Condic @ 2001-10-18 13:39 UTC (permalink / raw)


Fair enough. I just cut this code example off a page at AdaPower. You may
want to make a better one and submit it as a better example.

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/


"Jeffrey Carter" <jeffrey.carter@boeing.com> wrote in message
news:3BCE03AD.A20F87BF@boeing.com...
> Marin David Condic wrote:
> >
> > function Next_Line(File : in Ada.Text_IO.File_Type :=
> >    Ada.Text_Io.Standard_Input) return String is
>
> Ada.Text_IO.Current_Input would be a better default for this, so it can
> handle redirected input. This is the approach taken by
> PragmARC.Get_Line.
>
> --
> Jeffrey Carter





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

* Re: HELP!!!!!!
  2001-10-18  8:11     ` HELP!!!!!! Martin Dowie
@ 2001-10-18 16:57       ` Jeffrey Carter
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Carter @ 2001-10-18 16:57 UTC (permalink / raw)


Martin Dowie wrote:
> 
> "F" <phosphorus@libero.it> wrote in message
> news:9qlv2v$25md$1@newsreader1.mclink.it...
> > My problem is the second time i recall the function read string, in fact
> the
> > value of the function end_of_line remains true after the first time in
> wich
> > the user press return.....
> > II'm trying to use the procedure get_line instead of  get, i'll give you
> > news about this "experiment"
> > Thank you for your help
> 
> Have you tried flushing the keyboard buffer?

Calling Skip_Line might be better.

-- 
Jeffrey Carter



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

end of thread, other threads:[~2001-10-18 16:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-17 14:34 HELP!!!!!! F
2001-10-17 16:10 ` HELP!!!!!! Chris M. Moore
2001-10-17 16:36   ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
2001-10-17 18:17   ` HELP!!!!!! Jeffrey Carter
2001-10-18  7:10   ` HELP!!!!!! F
2001-10-18  8:11     ` HELP!!!!!! Martin Dowie
2001-10-18 16:57       ` HELP!!!!!! Jeffrey Carter
2001-10-17 16:28 ` How to read in very long strings. (was: HELP!!!!!!) Marin David Condic
2001-10-17 22:18   ` Jeffrey Carter
2001-10-18 13:39     ` Marin David Condic
2001-10-17 17:31 ` HELP!!!!!! tmoran

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