count_string program

From: Cecilia Chew (cecilia_at_nowhere.com)
Date: 02/26/04


Date: Thu, 26 Feb 2004 17:10:03 +0800

Hi all,
I am doing a program that will count the input characters from user.
There is a problem that I can't solve.
Problem is : since I'm going to count the characters. So, I can't ask
user how many characters they want to input. Compilation error come and
mention that the string need to be constrainted.
How am I going to constraint the string type since I don't know how many
characters user going to input.

Program is as follow:

========================================================================
with Ada.Text_Io, Ada.Integer_Text_Io;
use Ada.Text_Io, Ada.Integer_Text_Io;

procedure Count_String is
    type String is array (Positive range <>) of Character;
    Input : String;
    Count : Integer;
begin
    Count := 0;
    Put ("Please enter a string :");
    for I in Input'Range loop
       Get(Input(I));
       Count := Count + 1;
    end loop;
    New_Line;
    Put ("There are" & Integer'Image(Count) & " characters");
end Count_String;
=========================================================================

Problem occured at input : string;
with compilation error: unconstrainted subtype not allowed.
Please give any comments to this program. Thank you.

-- 
Cecilia Chew
c e c i l i a <AT> g r e e n l i m e . c o m


Relevant Pages

  • Re: Get the path and namefile in run time
    ... function Get_Path_Only return String; ... -- This returns the first N characters of the program name. ... end loop; ...
    (comp.lang.ada)
  • Re: Help a beginner - simple lowercase to uppercase and so on function
    ... And then one to loop across the string calling that function ... copying at to a new array. ... are any characters other than lowercase letters */ ...
    (comp.lang.c)
  • Re: An Example for Discussion
    ... Below is a string function I wrote this morning that will be going ... command in *nix does by default: given a list of "from" characters and a ... you're missing a 'for' loop. ... You end a 'while' loop with an increment. ...
    (comp.lang.c)
  • Re: Fast string operations
    ... Looping over characters like that can't slow things down that much. ... iteration through the string. ... a loop is going to start from the beginning of the ... the original issue was the amount of memory that is being consumed ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why the following code is faster executed when placed in the form?
    ... everything that is not changed inside the loop must not be calculated there. ... Some of the characters you use are predefined as ... It allocates memory for Chr/in your case you can add call to Chr/. ... Now imaging if you build extremely big string, ...
    (microsoft.public.vb.general.discussion)