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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a62337baf9692b50 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Stefan Merwitz Newsgroups: comp.lang.ada Subject: Re: Input a string Date: Fri, 28 Jan 2005 15:56:58 +0100 Message-ID: <35v246F4s0ev5U1@individual.net> References: <35t138F4pufluU1@individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net qf78PS1jaUXh7h4XRbHnmgeNF3oLGIsLxWpXAXiIMVDkcaFxLT User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:8055 Date: 2005-01-28T15:56:58+01:00 List-Id: Thanks, Nick But I have another problem: If your code is run after a Get(Character), the user doesn't get the possibilty to enter anything in your code. I guess there's some kind of key buffer that hasn't been emptied. How do I prevent the program from skipping your source? Source: Description: String(1..30); -- constrained Desc_Length: Natural range 0..Description'Last; ... begin ... Get(Character_Type); Get_Line(Description,Desc_Length); if Desc_Length = Description'Last then Skip_Line; end if; Thanks in advance, Stefan Nick Roberts schrieb: > Stefan Merwitz wrote: > > >>I need to input a string from the user. For integers I use >>Get(IntegerType). But unfortunately this doesn't seem to work for strings >>("unconstrained subtype not allowed"). How do I input a string and >>futhermore how to return the first 30 letters if the string is longer than >>30 chars? > > > I'll assume I'm not doing your homework for you :-) > > One simple soultion is: > > Description: String(1..30); -- constrained > Desc_Length: Natural range 0..Description'Last; > ... > begin > ... > Get_Line(Description,Desc_Length); > if Desc_Length = Description'Last then Skip_Line; end if; > > If the (remaining) text on the current line is less than 30 characters, the > line will be read into Description(1..Desc_Length). If the text is longer > than 30 characters, the first 30 will be put into Description, and the rest > will be skipped, and Desc_Length will be set to 30. Either way, the file > pointer will be moved to the beginning of the next line. (Untested.) > > Does this help you? There are certainly various other ways to do it. >