From: Jerry <lanceboyle@qwest.net>
Subject: Weird string I/O problem
Date: Tue, 25 Nov 2008 21:52:02 -0800 (PST)
Date: 2008-11-25T21:52:02-08:00 [thread overview]
Message-ID: <c6f5748b-923f-4077-b33e-a5017309ac46@w39g2000prb.googlegroups.com> (raw)
The following program misbehaves if the line
Get(A_Float); -- PROBLEMATIC LINE
is present; the call to Get_Line is made but there is no opportunity
for the user to enter a string--the program continues (I suppose) as
though the user entered a line terminator, causing the following
output:
Enter a float: 12.3
Enter a string: Hello from Get_Line.
Your string was
It was 0 long.
However, if the problematic line is commented out, the following
occurs:
Enter a float: Enter a string: Hello from Get_Line.
bla bla
Your string was bla bla
It was 7 long.
Here is the program:
with
Ada.Text_IO,
Ada.Float_Text_IO,
Ada.Strings.Unbounded;
use
Ada.Text_IO,
Ada.Float_Text_IO,
Ada.Strings.Unbounded;
procedure temp1 is
-- Crude Get_Line for unbounded strings.
procedure Get_Line(An_Unbounded_String : out Unbounded_String) is
Max_Length : Integer := 256;
A_String : String(1 .. Max_Length);
Length : Integer;
begin
Put_Line("Hello from Get_Line.");
Get_Line(A_String, Length);
An_Unbounded_String := To_Unbounded_String(A_String(1 ..
Length));
end Get_Line;
UBS : Unbounded_String;
A_Float : Float;
begin
Put("Enter a float: ");
Get(A_Float); -- PROBLEMATIC LINE
Put("Enter a string: ");
Get_Line(UBS);
Put_Line("Your string was " & To_String(UBS));
Put_Line("It was" & Length(UBS)'img & " long.");
end temp1;
What is going on here? I am running GNAT 4.3 on OS X 10.4.
Jerry
next reply other threads:[~2008-11-26 5:52 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-26 5:52 Jerry [this message]
2008-11-26 7:24 ` Weird string I/O problem christoph.grein
2008-11-26 7:38 ` christoph.grein
2008-11-26 8:25 ` Dmitry A. Kazakov
2008-11-26 9:07 ` Jean-Pierre Rosen
2008-11-26 15:21 ` John McCormick
2008-11-26 15:56 ` Adam Beneschan
2008-11-27 10:13 ` Jean-Pierre Rosen
2008-12-01 16:17 ` Adam Beneschan
2008-11-27 4:46 ` Jerry
2008-11-27 10:27 ` Jean-Pierre Rosen
2008-12-01 19:47 ` anon
2008-12-02 5:44 ` christoph.grein
2008-12-02 6:55 ` anon
2008-12-02 7:53 ` christoph.grein
2008-12-02 16:39 ` Adam Beneschan
2008-12-03 9:16 ` anon
2008-12-03 10:42 ` christoph.grein
2008-12-03 12:21 ` John B. Matthews
2008-12-04 0:15 ` anon
2008-12-04 7:31 ` christoph.grein
2008-12-04 7:56 ` Ludovic Brenta
2008-12-04 8:46 ` Georg Bauhaus
2008-12-03 11:35 ` stefan-lucks
2008-12-04 0:27 ` anon
2008-12-04 8:58 ` stefan-lucks
2008-12-04 22:54 ` anon
2008-12-05 9:06 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox