Simvik

Count a character

Loop over text and count matches. An easy embedded C problem (Arrays and text), run and graded in the browser.

easy · Arrays and text · strings · counting

Return how many times the character c appears in text. Upper and lower case are different characters.

Starter code

int count_char(const char text[], char c) {
  return 0;
}

Example tests

Several matches

printf("%d\n", count_char("banana", 'a'));

Expected output:

3

No match

printf("%d\n", count_char("banana", 'z'));

Expected output:

0

Learn it first

  • Arrays and text · Many values under one name, looping over them safely, and strings.

More Arrays and text problems