From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Get_Line
Date: Thu, 31 Oct 2002 16:55:24 -0500
Date: 2002-10-31T16:55:24-05:00 [thread overview]
Message-ID: <us39mdmb57bo51@corp.supernews.com> (raw)
In-Reply-To: B7Cv9.32984$iV1.11543@nwrddc02.gnilink.net
"Justin Birtwell" <jbirtwell@yahoo.com> wrote in message
news:B7Cv9.32984$iV1.11543@nwrddc02.gnilink.net...
>
> I'm having some strange behavior with Get_Line. In a procedure called
> GetData I call Get_Line to receive input from the command line. The first
> time this function is called it behaves fine prompting the user for input.
> The second time it runs the execution passes through Get_Line and no
prompt
> appears on the command line. Upon doing a little research in the Ref Man.
> I found a statement that talks about if Get_Line finds a line terminator
it
> automatically returns. But how can this be?
You might want to read my get_line article at adapower:
http://www.adapower.com/lang/get_line.html
Get_Line indicates that the entire line has been consumed by returning fewer
characters in the read request than are available in the buffer.
For example:
declare
Max_Length : constant := 80;
Line : String (1 .. Max_Length + 1);
Last : Natural;
begin
Get_Line (Line, Last);
if Last < Line'Last then
--entire line was consumed
else
--entire line was NOT consumed
end if;
end;
There are two approaches for handling the case that not all input was
consumed:
1) decide by fiat that the input was too long, and demand that the user
enter something shorter:
Line : String (1 .. Max_Length + 1);
Last : Natural;
Read_Response:
loop
Put ("ready: ");
Get_Line (...);
exit when Last < Line'Last;
Skip_Line;
Put_Line ("input too long; try again");
end loop Read_Response;
2) simply copy what you read into an unbounded string, and then consume the
rest of the line as necessary:
Input : Unbounded_String;
Put ("ready: ");
Read_Response:
loop
declare
...
begin
Get_Line (...);
Append (Input, Line (Line'First .. Last));
exit when Last < Line'Last;
end;
end Read_Response;
These two techniques will satisfy the majority of most programmers' needs.
next prev parent reply other threads:[~2002-10-31 21:55 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-29 20:24 Get_Line Justin Birtwell
2002-10-29 20:55 ` Get_Line David C. Hoos
2002-10-30 1:30 ` Get_Line Jeffrey Carter
2002-10-30 13:33 ` Get_Line Justin Birtwell
2002-10-30 14:40 ` Get_Line Preben Randhol
2002-10-30 17:09 ` Get_Line Jean-Pierre Rosen
2002-10-30 18:08 ` Get_Line Jeffrey Carter
2002-10-30 22:42 ` Get_Line Robert A Duff
2002-10-31 0:26 ` Get_Line Chad R. Meiners
2002-10-31 0:44 ` Get_Line Robert A Duff
2002-10-31 10:32 ` Get_Line John English
2002-10-31 11:30 ` Get_Line Preben Randhol
2002-10-31 13:10 ` Get_Line John English
2002-10-31 17:39 ` Get_Line Warren W. Gay VE3WWG
2002-10-31 21:46 ` Get_Line Chad R. Meiners
2002-11-01 16:59 ` Get_Line Robert A Duff
2002-11-01 21:04 ` Get_Line Chad R. Meiners
2002-11-01 23:32 ` Get_Line Matthew Heaney
2002-11-02 0:28 ` Get_Line Chad R. Meiners
2002-10-31 8:53 ` Get_Line Preben Randhol
2002-10-31 18:04 ` Get_Line Jeffrey Carter
2002-11-01 11:18 ` Get_Line Preben Randhol
2002-10-30 14:44 ` Get_Line Preben Randhol
2002-10-31 21:55 ` Matthew Heaney [this message]
-- strict thread matches above, loose matches on Subject: below --
1999-07-02 0:00 GET LINE babefan
1999-07-02 0:00 ` czgrr
1998-06-05 0:00 get_line Steve Dyrdahl
1998-06-05 0:00 ` get_line Samuel Mize
1998-06-17 0:00 ` get_line Hans Marqvardsen
1998-06-18 0:00 ` get_line John McCabe
1998-06-21 0:00 ` get_line Robert Dewar
1998-06-06 0:00 ` get_line Dale Stanbrough
1998-06-06 0:00 ` get_line Matthew Heaney
1998-06-07 0:00 ` get_line Dale Stanbrough
1998-06-06 0:00 ` get_line Matthew Heaney
1998-06-18 0:00 ` get_line Robert I. Eachus
1998-06-06 0:00 ` get_line Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox