count_string program
From: Cecilia Chew (cecilia_at_nowhere.com)
Date: 02/26/04
- Next message: Dmitry A. Kazakov: "Re: In-Out Parameters for functions"
- Previous message: Preben Randhol: "Re: In-Out Parameters for functions"
- Next in thread: Jacob Sparre Andersen: "Re: count_string program"
- Reply: Jacob Sparre Andersen: "Re: count_string program"
- Reply: Björn Persson: "Re: count_string program"
- Reply: Stephen Leake: "Re: count_string program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Dmitry A. Kazakov: "Re: In-Out Parameters for functions"
- Previous message: Preben Randhol: "Re: In-Out Parameters for functions"
- Next in thread: Jacob Sparre Andersen: "Re: count_string program"
- Reply: Jacob Sparre Andersen: "Re: count_string program"
- Reply: Björn Persson: "Re: count_string program"
- Reply: Stephen Leake: "Re: count_string program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|