logo CodeStepByStep logo

countOccurrences

Language/Type: C strings
Author: Cynthia Lee (on 2016/10/02)

Write a function named countOccurrences 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 countOccurrences("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 problem. 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

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

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.