1. puts() quirk

Dear List

I don't know if anyone's noticed this before ... maybe it's old news.

	sequence a
	sequence b

	a = { 'c', 'a', 't', 0, 0, 0 }
	b = "dog"

	puts( 1, a & "\n"  )
	puts( 1, b )

This outputs
	catdog
Rather than
	cat
	dog
As one might expect.

Indeed, if one combines the puts() into one, e.g.
	puts( 1, a & "\n" & b )
then the program outputs
	cat

Weird.

Bruce.
(Windows 2000 Advanced Server, Euphoria 2.4 beta, DOS32 script in a 
CMD.EXE window)

new topic     » topic index » view message » categorize

2. Re: puts() quirk

Actually, this makes perfect sense.  Strings in most C-based modern
languages are null terminated.  Any bytes after the null are considered
garbage and thus not part of the string.  Since Euphoria's string
handling is largely based on C routines, the first puts will see
"cat\0\0\0\n", will see the first null (\0) and will stop the string at
that point.  Since it never saw the newline, it never printed it.  The
same is true for your second example.

HTH,
Mike Sabal

>>> bruce_axtens at sil.org 04/23/03 04:53AM >>>
Dear List

I don't know if anyone's noticed this before ... maybe it's old news.

	sequence a
	sequence b

	a = { 'c', 'a', 't', 0, 0, 0 }
	b = "dog"

	puts( 1, a & "\n"  )
	puts( 1, b )

This outputs
	catdog
Rather than
	cat
	dog
As one might expect.

Indeed, if one combines the puts() into one, e.g.
	puts( 1, a & "\n" & b )
then the program outputs
	cat

Weird.

Bruce.
(Windows 2000 Advanced Server, Euphoria 2.4 beta, DOS32 script in a 
CMD.EXE window)



TOPICA - Start your own email discussion group. FREE!

new topic     » goto parent     » topic index » view message » categorize

3. Re: puts() quirk

What is going on with Topica that it's cutting off the top of all the
emails?!?!?

In case you don't get the above line, I'll repeat it below...

What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?
What is going on with Topica that it's cutting off the top of all the
emails?!?!?

----- Original Message -----
From: <Sabal.Mike at notations.com>
To: "EUforum" <EUforum at topica.com>
Sent: Wednesday, April 23, 2003 7:50 AM
Subject: Re: puts() quirk


> HTH,
> Mike Sabal
>
> >>> bruce_axtens at sil.org 04/23/03 04:53AM >>>
> Dear List
>
> I don't know if anyone's noticed this before ... maybe it's old news.
>
> sequence a
> sequence b
>
> a = { 'c', 'a', 't', 0, 0, 0 }
> b = "dog"
>
> puts( 1, a & "\n"  )
> puts( 1, b )
>
> This outputs
> catdog
> Rather than
> cat
> dog
> As one might expect.
>
> Indeed, if one combines the puts() into one, e.g.
> puts( 1, a & "\n" & b )
> then the program outputs
> cat
>
> Weird.
>
> Bruce.
> (Windows 2000 Advanced Server, Euphoria 2.4 beta, DOS32 script in a
> CMD.EXE window)
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: puts() quirk

Bruce M. Axtens wrote:
> I don't know if anyone's noticed this before ... maybe it's old news.
> 
>     sequence a
>     sequence b
> 
>     a = { 'c', 'a', 't', 0, 0, 0 }
>     b = "dog"
> 
>     puts( 1, a & "\n"  )
>     puts( 1, b )
> 
> This outputs
>     catdog
> Rather than
>     cat
>     dog
> As one might expect.

Yes, that's old news.
If you want to output 0's, you should open a file
in "wb" (binary mode) and write to it. File 1 (standard output)
is opened in "w" mode (text mode), and it doesn't
handle 0's as you'd like. Also \n is converted to \r\n
which you might not like either. Someone recently asked for a
routine to force standard output into binary mode,
and I'm looking into it.

Regards,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: puts() quirk

These lines
may be deleted
by Topica ...

Hello Bruce,

you wrote:

> I don't know if anyone's noticed this before ... maybe it's old news.
>
> 	sequence a
> 	sequence b
>
> 	a = { 'c', 'a', 't', 0, 0, 0 }
> 	b = "dog"
>
> 	puts( 1, a & "\n"  )
> 	puts( 1, b )
>
> This outputs
> 	catdog
> Rather than
> 	cat
> 	dog
> As one might expect.
>
> Indeed, if one combines the puts() into one, e.g.
> 	puts( 1, a & "\n" & b )
> then the program outputs
> 	cat
>
> Weird.

A byte with value 0, and all other bytes after that in the argument of
puts(), are ignored by the console window.
AFAIK that is the standard behaviour of the console output.

> Bruce.
> (Windows 2000 Advanced Server, Euphoria 2.4 beta, DOS32 script in a
> CMD.EXE window)

Best regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |
 \ /  against HTML in       |  Money is the root of all evil.
  X   e-mail and news,      |  Send 20 Dollars for more info.
 / \  and unneeded MIME     |

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu