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 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
feof
beforefgetc
won't stopfgetc
from reading theEOF
character0xff
once.Notice the extra
ff
on the end.ReaderUtil's
read_char
makes the same mistake of checkingfeof
before 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.