1use std::fs::{self, File};
2use std::io::{self, BufRead, BufReader, Write};
3use std::path::Path;
4
5fn read_lines<P: AsRef<Path>>(path: P) -> io::Result<Vec<String>> {
6 let file = File::open(path)?;
7 let reader = BufReader::new(file);
8 reader.lines().collect()
9}
10
11fn write_file<P: AsRef<Path>>(path: P, content: &str) -> io::Result<()> {
12 let mut file = File::create(path)?;
13 file.write_all(content.as_bytes())?;
14 Ok(())
15}
16
17fn process_file(input: &str, output: &str) -> Result<(), Box<dyn std::error::Error>> {
18 let lines = read_lines(input)?;
19 let processed: Vec<String> = lines
20 .iter()
21 .filter(|line| !line.trim().is_empty())
22 .map(|line| line.trim().to_uppercase())
23 .collect();
24
25 write_file(output, &processed.join("\n"))?;
26 println!("Processed {} lines", processed.len());
27 Ok(())
28}
29
30fn main() {
31 if let Err(e) = process_file("input.txt", "output.txt") {
32 eprintln!("Error: {}", e);
33 std::process::exit(1);
34 }
35}