From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,87a926dbf0cf8cb1 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: newbie problem Date: 1998/12/05 Message-ID: #1/1 X-Deja-AN: 418917661 Sender: matt@mheaney.ni.net References: <3667EE11.6E94BA0F@interact.net.au> NNTP-Posting-Date: Sat, 05 Dec 1998 03:35:53 PDT Newsgroups: comp.lang.ada Date: 1998-12-05T00:00:00+00:00 List-Id: Graeme Wallace writes: > If I want to get user input for my program in the form of a string of > undefined length, how do I do so ? If I set the string length to, say: > > help_me_please : String(1..20); > > I seem to be stuck with a string exactly that size. What is the > variable assignment which allows the actual length of the user input to > determine the length of the string which the io system > (ada.text_io.)gets ? You have to allocate a buffer of some fixed size, as you have done. What is missing from your solution is declaration of a "last" object, whose value indicates the index value of the last valid character that was input. The standard idiom for doing this sort of thing is declare Line : String (1 .. 80); Last : Natural; begin Ada.Text_IO.Get_Line (Line, Last); ... Line (Line'First .. Last) ... end; The value of Last tells you how much of the buffer is actually in use. Be careful not to name the Last object "Length." That would be misleading, and potentially error-prone, because "last index value" and "length of input string" are two different concepts, and often have different values. They only have the same value here, because the first index value of the string happens to be 1.