comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: Weird string I/O problem
Date: Mon, 01 Dec 2008 19:47:15 GMT
Date: 2008-12-01T19:47:15+00:00	[thread overview]
Message-ID: <7bXYk.50433$_Y1.8162@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: c6f5748b-923f-4077-b33e-a5017309ac46@w39g2000prb.googlegroups.com

--
-- Build your own input routine.  Example:
--
with Ada.Characters.Latin_1 ; -- Needed for control chars.
use Ada.Characters.Latin_1 ;

-- ...
  char : character ;
  input_string : String ( 1..80 ) ;
  last : natural ;

-- ...

input_string := ( others => nul ) ;
for index in input_string'Range loop
  Get ( char ) ;
  exit when char = CR or char = LF ;
  input_string ( index ) := char ;
  Last := Index ;  
end loop

  -- valid data is input_string ( 1 .. last ) ; with no term control characters

-- ...

In <c6f5748b-923f-4077-b33e-a5017309ac46@w39g2000prb.googlegroups.com>, Jerry <lanceboyle@qwest.net> writes:
>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
>




  parent reply	other threads:[~2008-12-01 19:47 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-26  5:52 Weird string I/O problem Jerry
2008-11-26  7:24 ` 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 [this message]
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