-
Notifications
You must be signed in to change notification settings - Fork 1
/
17.rs
32 lines (28 loc) · 983 Bytes
/
17.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::io;
/// Print all input lines that are longer than 80 characters.
fn main ()
{
// a mutable variable to hold input data
let mut input = String::new();
// using rust infinite loop
loop {
match io::stdin().read_line(&mut input) {
// io::Result::Ok receives the number of bytes read
Ok (n_bytes) => {
// case EOF is reached, "read_lines" will return 0 and we break out of the loop
if n_bytes == 0 {
break;
}
// In Rust it's a bit easier to do...
if input.chars().count() > 80 {
println!("SIZE: {:04} | \"{}\"", input.chars().count(), input);
}
// we need to clear input buffer because "read_line" appends all read bytes to it
input.clear();
},
Err(_) => {
panic!("Unexpected error.");
}
}
}
}