Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


devel / comp.lang.ada / Get_Line skip input

SubjectAuthor
* Get_Line skip inputRichard Iswara
+- Re: Get_Line skip inputNiklas Holsti
`* Re: Get_Line skip inputJeffrey R. Carter
 `- Re: Get_Line skip inputRichard Iswara

1
Get_Line skip input

<sg798l$3r0$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5719&group=comp.lang.ada#5719

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!mRBVMlGoFUnDsRgMYRJiSw.user.46.165.242.75.POSTED!not-for-mail
From: haujekch...@gmail.com (Richard Iswara)
Newsgroups: comp.lang.ada
Subject: Get_Line skip input
Date: Thu, 26 Aug 2021 12:36:18 +0700
Organization: Aioe.org NNTP Server
Message-ID: <sg798l$3r0$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="3936"; posting-host="mRBVMlGoFUnDsRgMYRJiSw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
X-Mozilla-News-Host: snews://nntp.aioe.org:563
 by: Richard Iswara - Thu, 26 Aug 2021 05:36 UTC

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);
Ada.Text_IO.New_Line;
end loop;
end;

Before I put the two lines marked above, the executable only skipped the
first instance of keyword entry.
After I put those two lines, the executable completely skipped the
Get_Line part.
So on the terminal it shows like this:
Keywords number 1 = Enter Multiplier for keyword <here cursor wait for
entry>
Keywords number 2 = Enter Multiplier for keyword <here cursor wait for
entry>

If I modifies the line marked + into Get (Key_Words (i) (1..W_Len(i)))
the compiler complain I did not assign W_Len. Most likely I get the
syntax incorrect.

What do I do wrong on the original code?

Re: Get_Line skip input

<ioovqbFcgalU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5720&group=comp.lang.ada#5720

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.h...@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Get_Line skip input
Date: Thu, 26 Aug 2021 10:56:59 +0300
Organization: Tidorum Ltd
Lines: 37
Message-ID: <ioovqbFcgalU1@mid.individual.net>
References: <sg798l$3r0$1@gioia.aioe.org>
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: <sg798l$3r0$1@gioia.aioe.org>
Content-Language: en-US
 by: Niklas Holsti - Thu, 26 Aug 2021 07:56 UTC

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.

Re: Get_Line skip input

<sg7lom$oj6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5721&group=comp.lang.ada#5721

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.not.acm.org (Jeffrey R. Carter)
Newsgroups: comp.lang.ada
Subject: Re: Get_Line skip input
Date: Thu, 26 Aug 2021 11:09:41 +0200
Organization: Also freenews.netfront.net; news.tornevall.net;
news.eternal-september.org
Lines: 104
Message-ID: <sg7lom$oj6$1@dont-email.me>
References: <sg798l$3r0$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 26 Aug 2021 09:09:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e07e4055dbc54f2235c1cd0a2c50c8c";
logging-data="25190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4h0JGmEymLFtqQfYEYKjukCfKie9nBWE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:JEeD92IkmaCmxlVrqzrEEhU+6MI=
In-Reply-To: <sg798l$3r0$1@gioia.aioe.org>
Content-Language: en-US
 by: Jeffrey R. Carter - Thu, 26 Aug 2021 09:09 UTC

On 8/26/21 7:36 AM, Richard Iswara wrote:
>
> So on the terminal it shows like this:
> Keywords number 1 =  Enter Multiplier for keyword <here cursor wait for entry>
> Keywords number 2 =  Enter Multiplier for keyword <here cursor wait for entry>

I set Kw_Numbers to 3 and added an output loop after the input loop:

for I in Key_Words'Range loop
Ada.Text_IO.Put_Line (Item => I'Image & ' ' &
Key_Words (I) (1 .. W_Len (I) ) &
Multiplier (I)'Image);
end loop;

I am unable to duplicate this behavior:

~/Code$ ./kw_test
Enter keywords less than 10 characters.
Keywords number 1 = one
Enter multiplier for keyword 7

Keywords number 2 = Enter multiplier for keyword 6

Keywords number 3 = Enter multiplier for keyword 3

1 one 7
2 6
3 3

As Holsti explained, this behavior is due to Ada.Integer_Text_IO.Get behaving as
specified, leaving the rest of the line available to Get_Line:

~/Code$ ./kw_test
Enter keywords less than 10 characters.
Keywords number 1 = one
Enter multiplier for keyword 7

Keywords number 2 = Enter multiplier for keyword 6

Keywords number 3 = Enter multiplier for keyword 3

1 one 7
2 6
3 3
~/Code$ ./kw_test
Enter keywords less than 10 characters.
Keywords number 1 = one
Enter multiplier for keyword 7two

Keywords number 2 = Enter multiplier for keyword 6three

Keywords number 3 = Enter multiplier for keyword 3

1 one 7
2 two 6
3 three 3

In general, I recommend obtaining a complete line and parsing it, rather than
inputting values with Get:

Get_Mult : loop
Ada.Text_IO.Put (Item => "Enter multiplier for keyword ");

One_Mult : declare
Line : constant String := Ada.Text_IO.Get_Line;
begin -- One_Mult
Multiplier (I) := Integer'Value (Line);

exit Get_Mult;
exception -- One_Mult
when others =>
Ada.Text_IO.Put_Line (Item => "Enter an non-negative integer");
end One_Mult;
end loop Get_Mult;

In general such code has to handle errors in the input. Users will input key
words > the specified max and non-numeric multipliers. Error handling is
simplified if one obtains complete lines (using the Get_Line function) and deals
with them.

Back in the Good Old Days (TM), I started off using FORTRAN 66 (it was always
written FORTRAN because the keypunches only had capital letters), where the only
data structure was the array. Things that would be an array of records in a
decent language were represented as groups of parallel arrays. That seems to be
what you're doing here.

subtype KW_Name_Length is Integer range 0 .. 10;

type Key_Word_Info (Length : KW_Name_Length := 0) is record
Name : String (1 .. Length);
Multiplier : Natural;
end record;

Num_KW : constant := 3;

type KW_List is array (1 .. Num_KW) of Key_Word_Info;

Key_Word : KW_List;

--
Jeff Carter
"Why don't you bore a hole in yourself and let the sap run out?"
Horse Feathers
49

Re: Get_Line skip input

<sg9k7k$keb$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5731&group=comp.lang.ada#5731

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!mRBVMlGoFUnDsRgMYRJiSw.user.46.165.242.75.POSTED!not-for-mail
From: haujekch...@gmail.com (Richard Iswara)
Newsgroups: comp.lang.ada
Subject: Re: Get_Line skip input
Date: Fri, 27 Aug 2021 09:55:45 +0700
Organization: Aioe.org NNTP Server
Message-ID: <sg9k7k$keb$1@gioia.aioe.org>
References: <sg798l$3r0$1@gioia.aioe.org> <sg7lom$oj6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="20939"; posting-host="mRBVMlGoFUnDsRgMYRJiSw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Richard Iswara - Fri, 27 Aug 2021 02:55 UTC

On 26/08/2021 16.09, Jeffrey R. Carter wrote:
> On 8/26/21 7:36 AM, Richard Iswara wrote:
>>
>> So on the terminal it shows like this:
>> Keywords number 1 =  Enter Multiplier for keyword <here cursor wait
>> for entry>
>> Keywords number 2 =  Enter Multiplier for keyword <here cursor wait
>> for entry>
>
> I set Kw_Numbers to 3 and added an output loop after the input loop:
>
>    for I in Key_Words'Range loop
>       Ada.Text_IO.Put_Line (Item => I'Image & ' ' &
>                                     Key_Words (I) (1 .. W_Len (I) ) &
>                                     Multiplier (I)'Image);
>    end loop;
>
> I am unable to duplicate this behavior:
>
> ~/Code$ ./kw_test
> Enter keywords less than 10 characters.
> Keywords number 1 = one
> Enter multiplier for keyword 7
>
> Keywords number 2 = Enter multiplier for keyword 6
>
> Keywords number 3 = Enter multiplier for keyword 3
>
>  1 one 7
>  2  6
>  3  3
>
> As Holsti explained, this behavior is due to Ada.Integer_Text_IO.Get
> behaving as specified, leaving the rest of the line available to Get_Line:
>
> ~/Code$ ./kw_test
> Enter keywords less than 10 characters.
> Keywords number 1 = one
> Enter multiplier for keyword 7
>
> Keywords number 2 = Enter multiplier for keyword 6
>
> Keywords number 3 = Enter multiplier for keyword 3
>
>  1 one 7
>  2  6
>  3  3
> ~/Code$ ./kw_test
> Enter keywords less than 10 characters.
> Keywords number 1 = one
> Enter multiplier for keyword 7two
>
> Keywords number 2 = Enter multiplier for keyword 6three
>
> Keywords number 3 = Enter multiplier for keyword 3
>
>  1 one 7
>  2 two 6
>  3 three 3
>
> In general, I recommend obtaining a complete line and parsing it, rather
> than inputting values with Get:
>
> Get_Mult : loop
>    Ada.Text_IO.Put (Item => "Enter multiplier for keyword ");
>
>    One_Mult : declare
>       Line : constant String := Ada.Text_IO.Get_Line;
>    begin -- One_Mult
>       Multiplier (I) := Integer'Value (Line);
>
>       exit Get_Mult;
>    exception -- One_Mult
>    when others =>
>       Ada.Text_IO.Put_Line (Item => "Enter an non-negative integer");
>    end One_Mult;
> end loop Get_Mult;
>
> In general such code has to handle errors in the input. Users will input
> key words > the specified max and non-numeric multipliers. Error
> handling is simplified if one obtains complete lines (using the Get_Line
> function) and deals with them.
>
> Back in the Good Old Days (TM), I started off using FORTRAN 66 (it was
> always written FORTRAN because the keypunches only had capital letters),
> where the only data structure was the array. Things that would be an
> array of records in a decent language were represented as groups of
> parallel arrays. That seems to be what you're doing here.
>
> subtype KW_Name_Length is Integer range 0 .. 10;
>
> type Key_Word_Info (Length : KW_Name_Length := 0) is record
>    Name : String (1 .. Length);
>    Multiplier : Natural;
> end record;
>
> Num_KW : constant := 3;
>
> type KW_List is array (1 .. Num_KW) of Key_Word_Info;
>
> Key_Word : KW_List;
>
Thank you Niklas and Jeffrey for the explanation and the better way to
do an input message.
Regards,
Richard.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor