comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: count_string program
Date: Fri, 27 Feb 2004 06:49:38 GMT
Date: 2004-02-27T06:49:38+00:00	[thread overview]
Message-ID: <6MB%b.69233$4o.90172@attbi_s52> (raw)
In-Reply-To: 403eb73b$1_1@news.tm.net.my

placed the   type string is array (positive range <>) of character;  to
handle a variable number of characters?
> Isn't once the user push 'enter' button means their input is done.
 but
>   for I in Input'Range loop
>      Get(Input(I));
>      Count := Count + 1;
>   end loop;

  That loop does not check the character to see if it is "enter" (probably
ascii.cr), so it will continue to loop until Input is full of characters.
So if Input had room for, say, 50 characters, the program will demand 50
characters, even if none or all 50 of them are "enter", and then exit the
loop.  Count will of course be 50.  If you actually check the input
characters, and exit the loop when you see an "enter", then the count will
tell how many were entered.  BTW, why are you saving the characters in
Input?  The rest of the program never does anything with them.  You really
only need to hold a single input character while you test for "enter".

>   type String is array (Positive range <>) of Character;
  Ada automatically has exactly such a String type, so there is no
need to duplicate what's already there.

>   Input : String;
  A String is an "array of characters".  A particular string, like Input,
is an array of a certain number of characters.  It's like saying a Book is
a bunch of pages between two covers.  But any specific book has a certain
set number of pages.  If you want a string of varying length, look up
Ada.Strings.Unbounded   In the real world, you can probably assume most
users won't enter more than, say, 1,000 characters, so you could specify
that your program only handles a maximum of 1,000, and then declare

  Input : String(1 .. 1000);



  reply	other threads:[~2004-02-27  6:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-26  9:10 count_string program Cecilia Chew
2004-02-26 10:17 ` Jacob Sparre Andersen
2004-02-27  3:13   ` Cecilia Chew
2004-02-27 11:00     ` Jacob Sparre Andersen
2004-02-26 15:43 ` Björn Persson
2004-02-27  3:19   ` Cecilia Chew
2004-02-27  6:49     ` tmoran [this message]
2004-02-27 18:29       ` Björn Persson
2004-02-27 13:28 ` Stephen Leake
replies disabled

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