CJCoding With Joseph
15free / daySign inCreate account

Count One Letter While Stepping a char Pointer

Complete int countLetter(const char *s, char target) so it returns how many times target appears in the string s. Walk the pointer one character at a time and compare the character it points at.

main is already written: it reads a word on the first line and a single letter on the second line, then prints the count.

For the input:
banana
a

Print exactly what is shown in Expected Output.

Expected Output:

Count: 3

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
banana\na\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.