1. Printf() won't print x00?

Hello!

I'm taking my first steps with Euphoria. It seems straightforward enough, but I'm having a bit of difficulty outputting zeros to a file in hexadecimal mode.

Am I doing something wrong?

printf(fOut, x"00 00")

printf(fOut, x"00 08")

etc.

No errors are generated at run time. However, any time I include '00' as the first value in a hex string, printf() does nothing at all. I'm using Euphoria 4.0.3, interpreting with eui.

Thanks,

Linus

new topic     » topic index » view message » categorize

2. Re: Printf() won't print x00?

lruth said...

Hello!

I'm taking my first steps with Euphoria. It seems straightforward enough, but I'm having a bit of difficulty outputting zeros to a file in hexadecimal mode.

Am I doing something wrong?

printf(fOut, x"00 00")

printf(fOut, x"00 08")

etc.

No errors are generated at run time. However, any time I include '00' as the first value in a hex string, printf() does nothing at all. I'm using Euphoria 4.0.3, interpreting with eui.

Thanks,

Linus

The printf routine is designed to output FORMATTED text based on the data given to it. Normally it needs three parameters...

  1. The file handle
  2. The formatting string
  3. The data to format.

In the way you have used it, the 'formatting' string is x"00 08", which I suspect is not what you intended.

What were you hoping to output to the file? Were you trying to output two bytes, namely #00 and #08? If so, this might be better for you ...

puts(fOut, x"") 

The puts routine just copies the bytes from the second parameter to the output file.

If however, you were trying to get a string representation of the hex bytes, try this ...

printf(fOut, "%02x%02x", x"") 

or even this ...

include std/io.e 
writef(fOut, "[:02x][:02x]", x"") 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Printf() won't print x00?

Hi Derek,

Thank you for your informative response. I was trying to output the bytes #00 and #08, as part of a function to generate zip file headers. Talk about humbling.

-Linus

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

4. Re: Printf() won't print x00?

lruth said...

Talk about humbling.

Hang on. Is this Radio 4? Are we playing Just a minute? It's not very good playing online, via a keyboard. I should know, I've tried before.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu