comp.lang.ada
 help / color / mirror / Atom feed
From: matthew_heaney@acm.org (Matthew Heaney)
Subject: Re: Help: Get/Get_line
Date: 1998/05/17
Date: 1998-05-17T00:00:00+00:00	[thread overview]
Message-ID: <matthew_heaney-ya023680001705980116080001@news.ni.net> (raw)
In-Reply-To: 355E79FE.448@info.polymtl.ca


In article <355E79FE.448@info.polymtl.ca>, jslavich@info.polymtl.ca wrote:

(start of quote)
My problem is when I need
to invert the "get" and "get_line" like so:
...
begin
        get(number);
        ...
        get_line(name, number2); ...
end xx; 

        At the first prompt I enter an integer and as soon as I hit the return
key, it skips over the "get_line" command and doesn't prompt me to enter
a string.  I get no error from the "get_line" command.
(end of quote)

Here's your problem:

When you press Return to enter the value of Number at the prompt, Get reads
in and parses only the number itself, not the carriage return.  What
happens is that when you say Get_Line, the carriage return is still there,
and it reads _that_ one, instead of the one you want.

What you need to do is just add a statement that consumes the rest in the
line, including the carriage return, and then do the Get_Line.  So just add
a Skip_Line immediately following Get.

The code belows compiles and works as expected, using GNAT 3.10p under UNIX.

Hope that helps,
Matt

--STX
with Ada.Integer_Text_IO;
with Ada.Text_IO;

procedure Test_IO is

   Name : String (1 .. 50);
   Last : Natural;

   I : Integer;

begin

   Ada.Integer_Text_IO.Get (I);

--!!! Here's the new line:
   Ada.Text_IO.Skip_Line;

   Ada.Text_IO.Get_Line (Name, Last);

   Ada.Text_IO.Put_Line ("I is" & I'Img);
   Ada.Text_IO.Put_Line ("Name is '" & Name (1 .. Last) & "'");

end;




  reply	other threads:[~1998-05-17  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 [this message]
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     ` Assistance: Get/Get_line Anonymous
replies disabled

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