comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Problem with output using Ada.Text_IO.Put
Date: Sun, 20 Jul 2014 08:22:57 +0300
Date: 2014-07-20T08:22:57+03:00	[thread overview]
Message-ID: <c31219F90nbU1@mid.individual.net> (raw)
In-Reply-To: <6d5e2fff-e397-4c75-a3c9-3a7825d00752@googlegroups.com>

On 14-07-20 00:37 , junior learning ADA wrote:
> I am starting to learn ADA and I have installed Adacore gnat 2014. 

Welcome to the Ada community! And don't be offended if some of us insist
that it should be spelled Ada instead of ADA. This spelling thing is
something of an "in-joke" here. Now that you have been subjected to it,
you can consider yourself initiated into the community.

> I am using the source codes from M.B. Feldman and E.B. Koffman,
> Ada 95 Problem Solving and Program Design, 3rd edition.
> 
> In this respect, there appears to be a problem with Ada.Text_IO.Put
> and Ada.Integer_Text_IO.Get. The issue is that the text output
> only appears after the Ada.Integer_Text_IO.Get (Item => Nickels);

As others have answered, interactive Text_IO should not behave in that
way, but should behave as you expect it to do. (However -- and this is a
question for the other responders -- I did not yet find where in the Ada
Reference Manual this interactive behaviour is specified.)

> Please see extract from program:
> 
> BEGIN -- Coin_Collection
> 
>   -- prompt user for number of nickels and pennies
>   Ada.Text_IO.Put (Item => "How many nickels do you have? ");
>   Ada.Integer_Text_IO.Get (Item => Nickels);
>   Ada.Text_IO.Put (Item => "How many pennies do you have? ");
>   Ada.Integer_Text_IO.Get (Item => Pennies);
>   Ada.Text_IO.New_Line;
> 
> 
> However, when I run the program the text output appears after the questions. See below:
> /Users/francois/Documents/ADA/test/fk3-w95/coin_collection
> 1
> 2
> How many nickels do you have? How many pennies do you have? 
> [2014-07-19 22:05:16] process terminated successfully, elapsed time: 16.28s

It seems as if the process that executes your Ada program is treating
the Text_IO standard-output channel as a block-buffered channel, and is
not flushing the collected output when the program asks for some input
on the standard-input channel, as should happen for interactive,
non-buffered channels.

Are you running the program from a normal shell in a normal command
window, or in some special way? Which OS are you using? Are you using
some output-collecting tool such as "tee"? Please show us the command
line you use to run your program.

To understand the problem better, you could make some experiments:

- Try using Ada.Text_IO.Put_Line instead of Put (or, alternatively, add
a call of Ada.Text_IO.New_Line after each Put call). This experiment
should show us if your system treats standard-output as line-buffered
(but from the output you display, this is not the case).

- Try adding a call of Ada.Text_IO.Flush after every call to Put, at the
point where you expect the output from the Put to be visible as a prompt
for the user's input. This may counteract the output buffering that, for
some reason, is happening in your environment.


-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .

  parent reply	other threads:[~2014-07-20  5:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-19 21:37 Problem with output using Ada.Text_IO.Put junior learning ADA
2014-07-19 22:10 ` Jerry
2014-07-19 23:58 ` Jeffrey Carter
2014-07-20  5:22 ` Niklas Holsti [this message]
2014-07-20  6:52   ` junior learning ADA
2014-07-20  7:00     ` junior learning ADA
2014-07-20 14:51       ` Niklas Holsti
2014-07-20  8:53     ` Georg Bauhaus
2014-07-20 10:36     ` Simon Wright
replies disabled

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