comp.lang.ada
 help / color / mirror / Atom feed
From: nobody@REPLAY.COM (Anonymous)
Subject: Re: Assistance: Get/Get_line
Date: 1998/05/22
Date: 1998-05-22T00:00:00+00:00	[thread overview]
Message-ID: <199805221422.QAA07806@basement.replay.com> (raw)
In-Reply-To: 35645664.2AE1A75A@swl.msd.ray.com


<355E0DE6.6867@info.polymtl.ca> <356231EB.3F2@eurocopter.de>

On Thu, 21 May 1998 12:29:24 -0400, "John J Cupak Jr, CCP"
<jcj@swl.msd.ray.com> wrote:

[about using Text_Io to input Integers (or numbers in general)]

> ...
> Alternatively, if you use Get_Line(Line, Size) to read in the
> entire line, then you can use the Integer Get from a string to
> extract just the integer part (See RM A.10.8(15-16)):
> 
>    Get_Line(Line, Size);
>    Get(From => Line(1..Size), Item => Number, Last => Last);
> ...

This (or using 'Value) is similar to the approach I recommend. I either
use a "function Get_Line return String;" or put

if Size >= Line'Last then
   Skip_Line;
end if;

after the Get_Line. Then I'm sure the entire line is gone. If there is
an error in the input, error handling is simplified if the line is gone.
Using "Get (Number);" when there is an error in the input, the required
error handling is difficult. I've seen many programs that do

output prompt

loop
   begin
      Get (Number);

      exit;
   exception
   when others =>
      output "Invalid number; re-enter"
   end;
end loop;

that work fine when the input is correct. Type an "X" for the number and
it goes into an infinite loop. Using Get_Line and really getting the
entire line eliminates this common error.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"Now go away or I shall taunt you a second time."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




      parent reply	other threads:[~1998-05-22  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-16  0:00 Help: Get/Get_line John Slavich
1998-05-16  0:00 ` Matthew Heaney
1998-05-16  0:00 ` Tom Moran
1998-05-17  0:00   ` John Slavich
1998-05-17  0:00     ` Matthew Heaney
1998-05-17  0:00       ` John Slavich
1998-05-18  0:00         ` Dale Stanbrough
1998-05-20  0:00 ` christoph grein
1998-05-21  0:00   ` John J Cupak Jr, CCP
1998-05-22  0:00     ` Dale Stanbrough
1998-05-22  0:00     ` Anonymous [this message]
replies disabled

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