diff --git a/src/main.rs b/src/main.rs index e7a11a9..30843e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,29 @@ +use std::{fs, io::{self, BufRead, BufReader}}; + fn main() { + println!("Hello, world!"); } + +fn read_codes(code_file : &str) -> io::Result> { + let file = fs::File::open(code_file)?; + let reader = BufReader::new(file); + let mut codes = Vec::new(); + let mut line_count = 0; + for line in reader.lines() { + if let Ok(l) = line { + let r_str = l.as_str(); + let code_vec : Vec<&str> = r_str.split(' ').collect(); + if code_vec.len() == 2 { + let val1 : u32 = code_vec[0].parse().unwrap_or_default(); + let val2 : u32 = code_vec[1].parse().unwrap_or_default(); + codes.push(val1); + codes.push(val2); + } else { + println!("code error at line {}.", line_count); + } + } + line_count += 1; + } + Ok(codes) +}