* How it works get_line function
@ 2009-05-08 20:50 juanmiuk
2009-05-08 21:33 ` Jeffrey R. Carter
0 siblings, 1 reply; 3+ messages in thread
From: juanmiuk @ 2009-05-08 20:50 UTC (permalink / raw)
Hello All,
I tried to worked out how works the function get_line but gave me a
error:
with Ada.Text_Io;
use Ada.Text_Io;
procedure Read_String_func is
Line : String (1 .. 80);
begin
Put("Write a string: ");
Line := Get_Line;
end Read_String_Func;
Write a string: adfkjadfk
raised CONSTRAINT_ERROR : read_string_func.adb:11 length check failed
What I was doing wrong?
Thanks in advance
Juan Miguel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How it works get_line function
2009-05-08 20:50 How it works get_line function juanmiuk
@ 2009-05-08 21:33 ` Jeffrey R. Carter
2009-05-09 20:56 ` juanmiuk
0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey R. Carter @ 2009-05-08 21:33 UTC (permalink / raw)
juanmiuk wrote:
> with Ada.Text_Io;
> use Ada.Text_Io;
>
> procedure Read_String_func is
> Line : String (1 .. 80);
> begin
> Put("Write a string: ");
> Line := Get_Line;
> end Read_String_Func;
>
> Write a string: adfkjadfk
>
> raised CONSTRAINT_ERROR : read_string_func.adb:11 length check failed
>
> What I was doing wrong?
You were attempting to assign a 9-Character String to an 80-Character String.
When assigning arrays, both sides need to be the same size.
The Get_Line function is best suited to initializing a String object, or
providing a value to another subprogram:
S1 : constant String := Ada.Text_IO.Get_Line;
S2 : String := Ada.Text_IO.Get_Line;
Ada.Text_IO.Put_Line (Item => Ada.Text_IO.Get_Line);
--
Jeff Carter
"I like it when the support group complains that they have
insufficient data on mean time to repair bugs in Ada software."
Robert I. Eachus
91
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How it works get_line function
2009-05-08 21:33 ` Jeffrey R. Carter
@ 2009-05-09 20:56 ` juanmiuk
0 siblings, 0 replies; 3+ messages in thread
From: juanmiuk @ 2009-05-09 20:56 UTC (permalink / raw)
Hello Jeffrey,
First of all say thank you for you help. I got it, and I wrote a
program for show you:
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Read_String_func_1 is
begin
Put ("Type a String: ");
declare
Cadena : Constant String := Get_Line;
begin
Put("You typed: " & Cadena);
end;
New_Line;
Put("Type a Integer: ");
declare
Input : Constant String := Get_Line;
Num : Natural;
begin
Num := Natural'Value(Input);
Put ("You typed :" );
Put(Num, 6);
New_Line;
Put("Converted with Natural'Image is: " & Natural'Image(Num));
end;
end Read_String_Func_1;
On 8 May, 22:33, "Jeffrey R. Carter"
<spam.jrcarter....@nospam.acm.org> wrote:
> juanmiuk wrote:
> > with Ada.Text_Io;
> > use Ada.Text_Io;
>
> > procedure Read_String_func is
> > Line : String (1 .. 80);
> > begin
> > Put("Write a string: ");
> > Line := Get_Line;
> > end Read_String_Func;
>
> > Write a string: adfkjadfk
>
> > raised CONSTRAINT_ERROR : read_string_func.adb:11 length check failed
>
> > What I was doing wrong?
>
> You were attempting to assign a 9-Character String to an 80-Character String.
> When assigning arrays, both sides need to be the same size.
>
> The Get_Line function is best suited to initializing a String object, or
> providing a value to another subprogram:
>
> S1 : constant String := Ada.Text_IO.Get_Line;
>
> S2 : String := Ada.Text_IO.Get_Line;
>
> Ada.Text_IO.Put_Line (Item => Ada.Text_IO.Get_Line);
>
> --
> Jeff Carter
> "I like it when the support group complains that they have
> insufficient data on mean time to repair bugs in Ada software."
> Robert I. Eachus
> 91
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-05-09 20:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-08 20:50 How it works get_line function juanmiuk
2009-05-08 21:33 ` Jeffrey R. Carter
2009-05-09 20:56 ` juanmiuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox