1. Printf() won't print x00?
- Posted by lruth Dec 09, 2011
- 1239 views
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
2. Re: Printf() won't print x00?
- Posted by DerekParnell (admin) Dec 09, 2011
- 1238 views
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...
- The file handle
- The formatting string
- 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"")
3. Re: Printf() won't print x00?
- Posted by lruth Dec 09, 2011
- 1167 views
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
4. Re: Printf() won't print x00?
- Posted by petelomax Dec 09, 2011
- 1159 views
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.