str.c 283 B

12345678910111213
  1. /* CC0 (Public domain) - see LICENSE file for details */
  2. #include <ccan/str/str.h>
  3. size_t strcount(const char *haystack, const char *needle)
  4. {
  5. size_t i = 0, nlen = strlen(needle);
  6. while ((haystack = strstr(haystack, needle)) != NULL) {
  7. i++;
  8. haystack += nlen;
  9. }
  10. return i;
  11. }