diff --git a/src/c/funktionen.c b/src/c/funktionen.c index d7b310b..c1ba980 100644 --- a/src/c/funktionen.c +++ b/src/c/funktionen.c @@ -63,4 +63,16 @@ int string_character_counter(char string[]) { } return stringLength; +} + +int characterAppearanceInString(char c, char string[]) { + int appear = 0; + + for (int i = 0; i < string_character_counter(string); i++) { + if (string[i] == c) { + appear++; + } + } + + return appear; } \ No newline at end of file diff --git a/src/test/test_funktionen.c b/src/test/test_funktionen.c index 2f82c60..37852c4 100644 --- a/src/test/test_funktionen.c +++ b/src/test/test_funktionen.c @@ -121,4 +121,20 @@ void test_stringLaenge_von_Kokosnuss(void) TEST_ASSERT_EQUAL_INT(expected, actual); } +void test_howManyTimes_e_appearsIn_Beere(void) +{ + /* arrange */ + int actual; + int expected = 3; + + char c = 'e'; + char string[] = "Beere"; + + /* act */ + actual = characterAppearanceInString(c, string); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, actual); +} + #endif \ No newline at end of file