comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Get_Line skip input
Date: Thu, 26 Aug 2021 10:56:59 +0300	[thread overview]
Message-ID: <ioovqbFcgalU1@mid.individual.net> (raw)
In-Reply-To: <sg798l$3r0$1@gioia.aioe.org>

On 2021-08-26 8:36, Richard Iswara wrote:
> Why do Get_Line skipped the input? I have the following code:
> 
>     -- late declaration of Key words string array
>     declare
>        type Kw_Array is array (1 .. Kw_Numbers) of String (1 .. 10);
>        Key_Words : Kw_Array;
>        type W_Len_Array is array (1 .. Kw_Numbers) of Natural;
>        W_Len, Multiplier : W_Len_Array;
> 
>     begin
>        Ada.Text_IO.Put_Line ("Enter keywords less than 10 characters.");
>        for i in 1 .. Kw_Numbers loop
>           Ada.Text_IO.Put ("Keywords number ");
>           Ada.Integer_Text_IO.Put (i, 1);
>           Ada.Text_IO.Put (" = ");
> +         Ada.Text_IO.Get_Line (Key_Words (i), W_Len (i));
>  >         Ada.Text_IO.Put("Enter multiplier for keyword ");
>  >         Ada.Integer_Text_IO.Get(Multiplier(i),1);


Integer_Text_IO.Get does not read the /whole/ line that contains the 
multiplier -- it only reads the multiplier, but not the "end of line".
Insert this to skip (ignore) the rest of that input line and advance to 
the start of the next input line (which will hold the next keyword):

             Ada.Text_IO.Skip_Line;

>           Ada.Text_IO.New_Line;
>        end loop;
>     end;


As it was, because Integer_Text_IO.Get left the input pointer on the 
multiplier line, the next Get_Line read an empty next keyword (or 
whatever you typed on the multiplier line /after/ the multiplier 
digits), without needing more user input. Skip_Line should correct that.

  reply	other threads:[~2021-08-26  7:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  5:36 Get_Line skip input Richard Iswara
2021-08-26  7:56 ` Niklas Holsti [this message]
2021-08-26  9:09 ` Jeffrey R. Carter
2021-08-27  2:55   ` Richard Iswara
replies disabled

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