comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Input a string
Date: Thu, 27 Jan 2005 22:37:49 +0000
Date: 2005-01-27T22:37:49+00:00	[thread overview]
Message-ID: <gemini.iazyv100kpt6q008g.nick.roberts@acm.org> (raw)
In-Reply-To: 35t138F4pufluU1@individual.net

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.

-- 
Nick Roberts



  reply	other threads:[~2005-01-27 22:37 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 [this message]
2005-01-28 14:56   ` Stefan Merwitz
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