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 33 34 35
use std::fs::File; use std::io::Read; use std::error::Error; pub fn gender_identification(com: String) -> Result<(), Box<dyn Error>> { let mut text_boy = File::open("boysname.txt").unwrap(); let mut text_girl = File::open("girlsname.txt").unwrap(); let mut seperate_boy = String::new(); let mut seperate_girl = String::new(); text_boy.read_to_string(&mut seperate_boy).unwrap(); text_girl.read_to_string(&mut seperate_girl).unwrap(); let compare= com; let mut is_found_boy = false; let mut is_found_girl = false; for word in seperate_boy.split("\r\n"){ if word==compare{ is_found_boy = true; } } for word in seperate_girl.split("\r\n"){ if word==compare{ is_found_girl = true; } } if is_found_boy { println!("{}: Gender is Male ",compare); } else if is_found_girl{ println!("{} : Gender is Female ",compare); } else{ println!(".......sorry this name is not our Database......."); } Ok(()) }