From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Get_Line skip input Date: Thu, 26 Aug 2021 10:56:59 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net BYFH8UwliTOnWwoyljoaJA1dNAEc+zq4FO2NKiIwRxS8aruajH Cancel-Lock: sha1:ufqzf2etAp5S+SNV3EN03NzUyoE= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:62541 List-Id: 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.