comp.lang.ada
 help / color / mirror / Atom feed
* count_string program
@ 2004-02-26  9:10 Cecilia Chew
  2004-02-26 10:17 ` Jacob Sparre Andersen
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Cecilia Chew @ 2004-02-26  9:10 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-02-27 18:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2004-02-27 18:29       ` Björn Persson
2004-02-27 13:28 ` Stephen Leake

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