Skip to content

Instantly share code, notes, and snippets.

@ryochack
Last active December 28, 2016 06:39
Show Gist options
  • Select an option

  • Save ryochack/77d80c7718e2c310f7aee4915208cb9e to your computer and use it in GitHub Desktop.

Select an option

Save ryochack/77d80c7718e2c310f7aee4915208cb9e to your computer and use it in GitHub Desktop.
// 標準入力を受け取って標準出力に吐き出す
use std::io::{self, Read, Write};
fn main() {
const N: usize = 8;
let mut buf = [0u8; N];
loop {
match io::stdin().read(&mut buf) {
Ok(s) => {
if s == 0 {
break;
}
match buf[0] {
b'.' => break,
_ => {
print!(">");
let _ = io::stdout().write(&buf[0..s]);
}
}
}
Err(e) => {
println!("error: {}", e);
break;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment