← Back to Pointers
Question 448
Count One Letter While Stepping a char Pointer
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
Sign in to use hintsTopics:
Pointers
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.