Created
February 9, 2013 07:37
-
-
Save mcpherrinm/4744509 to your computer and use it in GitHub Desktop.
simple cat program that seems broken
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use io::ReaderUtil; | |
| fn main() { | |
| let file = path::Path("input"); | |
| let f = result::unwrap(io::file_reader(&file)); | |
| for f.each_char() |i| { | |
| io::print(fmt!("%c", i)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A similar program in c will cause a similar error.
Checking
feofbeforefgetcwon't stopfgetcfrom reading theEOFcharacter0xffonce.Notice the extra
ffon the end.ReaderUtil's
read_charmakes the same mistake of checkingfeofbefore blindly grabing the next character assuming it won't be theEOF.I started looking at fixing it but there's a lot of interdependency with read_bytes etc that I don't have time to grok right now.