logo CodeStepByStep logo

count_occurrences

Language/Type: C string
Related Links:
Author: Cynthia Lee (on 2018/02/03)

Write a function named count_occurrences that accepts a string to match (as char *), and a string to search (as a char *), and returns the number of different locations where the match string can be found in the string to search. For example, the call count_occurrences("ab", "abstract baabaa baobab") returns 3. If either string is NULL or empty, return 0.

Function: Write a C function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.