Here's an attempt in C:
#include <string.h>
int CountBob(const char * s)
{
int n = 0;
while (s = strstr(s, "bob")) {
n++;
s++;
}
return n;
}
int main()
{
char *s = "azcbobobegghakl";
int n = CountBob(s);
printf("Number of times bob occurs is: %d", n);
getchar();
}