comp.lang.ada
 help / color / mirror / Atom feed
From: Stefan Merwitz <thebiggestfan2002@yahoo.de>
Subject: Re: Input a string
Date: Fri, 28 Jan 2005 15:56:58 +0100
Date: 2005-01-28T15:56:58+01:00	[thread overview]
Message-ID: <35v246F4s0ev5U1@individual.net> (raw)
In-Reply-To: <gemini.iazyv100kpt6q008g.nick.roberts@acm.org>

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 <thebiggestfan2002@yahoo.de> 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.
> 



  reply	other threads:[~2005-01-28 14:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-27 20:27 Input a string Stefan Merwitz
2005-01-27 22:37 ` Nick Roberts
2005-01-28 14:56   ` Stefan Merwitz [this message]
2005-01-29  8:52     ` Stefan Merwitz
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox