diff --git a/Week-01/Day-02_Finding-Nemo/finding_nemo/Cargo.toml b/Week-01/Day-02_Finding-Nemo/finding_nemo/Cargo.toml new file mode 100644 index 0000000..6dd366a --- /dev/null +++ b/Week-01/Day-02_Finding-Nemo/finding_nemo/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "finding_nemo" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/Week-01/Day-02_Finding-Nemo/finding_nemo/src/main.rs b/Week-01/Day-02_Finding-Nemo/finding_nemo/src/main.rs new file mode 100644 index 0000000..3e8b103 --- /dev/null +++ b/Week-01/Day-02_Finding-Nemo/finding_nemo/src/main.rs @@ -0,0 +1,29 @@ +use std::io::{self, Write}; + +fn find_nemo(word: &str) -> Option { + for (i, word) in word.split(" ").enumerate() { + if word == "Nemo" { + return Some(i + 1); + } + } + + None +} + +fn main() { + let mut buffer = String::new(); + + print!("Insert your words: "); + io::stdout().flush().expect("Failed to flush stdout."); + + io::stdin() + .read_line(&mut buffer) + .expect("Error while trying to read from stdin."); + + let nemo = find_nemo(&buffer); + + match nemo { + Some(x) => println!("I found Nemo at {}!", x), + None => println!("I can't find Nemo :("), + } +}