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: Marin David Condic Subject: Re: newbie problem Date: 1998/12/04 Message-ID: <36680053.73036E4D@pwfl.com>#1/1 X-Deja-AN: 418641220 Content-Transfer-Encoding: 7bit Sender: condicma@nameserver.pwfl.com References: <3667EE11.6E94BA0F@interact.net.au> To: Graeme Wallace Content-Type: text/plain; charset=us-ascii Organization: Pratt & Whitney Mime-Version: 1.0 Reply-To: diespammer@pwfl.com Newsgroups: comp.lang.ada Date: 1998-12-04T00:00:00+00:00 List-Id: Graeme Wallace wrote: > > 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 ? > > G Wallace > > Thankyou. > :-) Ada.Text_IO does not have a Get or Get_Line procedure for variable length strings. You have to declare a string of some sufficiently large size to contain whatever you expect for input. (I usually use 256 bytes, figuring that it is more than generous) You should notice that the Get_Line procedure has a parameter "Last" which indicates the index of the last character read. You can make use of this in constructing variable length strings. See the following package specs: Ada.Strings (ARM A.4.1) Ada.Strings.Fixed (ARM A.4.3) Ada.Strings.Bounded (ARM A.4.4) Ada.Strings.Unbounded (ARM A.4.5) Between all of these - and a few related packages - you should find all of the string handling features you need. The .Fixed package gives you routines for handling the kinds of strings that Text_IO is going to give you while .Bounded and .Unbounded will give you a choice of dynamically sized strings & routines for handling them once you have read them in via Text_IO. I think a useful extension to the language would be variations on Text_IO which used Bounded and Unbounded strings. But for now its just Fixed. MDC -- Marin D. Condic Real Time & Embedded Systems, Propulsion Systems Analysis United Technologies, Pratt & Whitney, Large Military Engines M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600 Ph: 561.796.8997 Fx: 561.796.4669 "The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man." -- G.B. Shaw