mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2025-06-29 00:07:31 +02:00
Rename sheet folders to assure proper sorting
This commit is contained in:
19
aufgaben/sheet02/sol3/count.rs
Executable file
19
aufgaben/sheet02/sol3/count.rs
Executable file
@ -0,0 +1,19 @@
|
||||
//! Aufgabe 2.3
|
||||
|
||||
fn main() {
|
||||
let s = "The fat cat had a friend! ♥";
|
||||
let count = count(s, 'a');
|
||||
println!("{}", count);
|
||||
}
|
||||
|
||||
|
||||
fn count(haystack: &str, needle: char) -> u64 {
|
||||
let mut count = 0;
|
||||
for c in haystack.chars() {
|
||||
if c == needle {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
count
|
||||
}
|
Reference in New Issue
Block a user