Add solution for sheet2

This commit is contained in:
Lukas Kalbertodt
2016-11-15 23:42:34 +01:00
parent 671ec22f10
commit 95de881390
3 changed files with 123 additions and 0 deletions

19
aufgaben/sheet2/sol3/count.rs Executable file
View 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
}