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.

Type your C solution code here:


This is a function exercise. Write a C function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.