From: Adam Beneschan on
On Dec 18, 4:28 am, Paul <du...(a)telus.net> wrote:
> Hi, given the following two simple programs
>
> hello.adb
> -----------------------
> with ada.text_io;
> procedure hello is
> begin
> ada.text_io.put("hello");
> end hello;
> -----------------------
>
> hello.c
> -----------------------
> #include <stdio.h>
> int main()
> {
> printf("hello");}
>
> -----------------------
>
> the result for the ada program is:
> -----------------------
> $ ./hello_in_ada
> hello
> $
> -----------------------
>
> and for the c program:
> -----------------------
> $ ./hello_in_c
> hello$
> -----------------------
>
> The c program does not print a new-line, but the ada program does.
>
> Is there any way to make the ada program not print a new-line?
>
> And is this behavior part of the Ada standard or is it just part of gnat?

Regarding whether this is part of the Ada standard or not: this
actually is not a simple yes/no question. The Ada standard says that
when an output file is closed, the effect of New_Page takes place (A.
10.2(3)); this means that a "line terminator" is written if the
current line is not already terminated, and that a "page terminator"
is written if the current page is not already terminated. However,
"line terminator" and "page terminator" are logical concepts, and the
standard makes clear that they don't have to be represented by actual
characters in a file. (If, for example, an *input* text file on a
Unix-type system does not end in a newline, I believe a reasonable Ada
implementation would treat the logical end-of-file as a line
terminator, as well as a page terminator, even though there are no
bytes in the file to indicate the end of line.)

What this does mean, though, is that logically, it doesn't matter
whether the last output operation to the file is New_Line/Put_Line or
not. Thus, in some sense, these have the same effect:

...
Text_IO.Put_Line (File, "ABC");
Text_IO.Put (File, "DEF");
Text_IO.Close (File);

and

...
Text_IO.Put_Line (File, "ABC");
Text_IO.Put_Line (File, "DEF");
Text_IO.Close (File);

since in the second case, the last Put_Line will output a line
terminator; and in the first case, the Close will output a line
terminator because the current line hasn't yet been terminated.

So it doesn't surprise me that it's hard to use Text_IO to write a
text file that isn't terminated by newline. If you really want this,
you have to go "outside Ada" to tell the implementation something
about the actual bytes you want put into the file (Ada doesn't define
this). Some Ada implementations may provide this ability in the Form
parameter when you open the file.

Hope this helps,
-- Adam

From: Jeffrey R. Carter on
petter_fryklund(a)hotmail.com wrote:
>
> I tried GNAT 6.1.0w on Solaris. Got NL.

GNAT 6.1.0w on Linux does not output a line terminator with Kazakov's program.
This may be shell- or OS-specific, taking pains to always output the prompt on a
new line.

--
Jeff Carter
"From this day on, the official language of San Marcos will be Swedish."
Bananas
28
From: anon on
--
--
-- GNAT.IO and "System.IO" uses the "printf"
--
-- "Ada.Text_IO" uses "fprintf" because it is based on file stucture.
-- Since this package uses files it must closed and
-- the core library routine adds a NL character during
-- the closing process.
--
with Ada.Text_IO ;
with GNAT.IO ;
with System.IO ;

procedure y is

begin

Ada.Text_IO.Put ( "Testing NL" ) ;
GNAT.IO.Put ( "Testing NL" ) ;
System.IO.Put ( "Testing NL" ) ;
Ada.Text_IO.Put_Line ( "DONE" ) ;

end y ;

In <M1P9j.7718$wy2.3046(a)edtnps90>, Paul <duneo(a)telus.net> writes:
>Hi, given the following two simple programs
>
>
>hello.adb
>-----------------------
>with ada.text_io;
>procedure hello is
>begin
>ada.text_io.put("hello");
>end hello;
>-----------------------
>
>
>hello.c
>-----------------------
>#include <stdio.h>
>int main()
>{
> printf("hello");
>}
>-----------------------
>
>the result for the ada program is:
>-----------------------
>$ ./hello_in_ada
>hello
>$
>-----------------------
>
>and for the c program:
>-----------------------
>$ ./hello_in_c
>hello$
>-----------------------
>
>The c program does not print a new-line, but the ada program does.
>
>Is there any way to make the ada program not print a new-line?
>
>And is this behavior part of the Ada standard or is it just part of gnat?
>
>I looked for answers, but found none.
>
>Thanks,
>
>Paul Zacharzewski

From: Paul on
Thanks for all the replies.

Esp. Dimitri, and Adams insight.

I think Streams is exactly what I was looking for.

Paul.
 | 
Pages: 1
Prev: need hint for adabrowse usage
Next: Auto new line