Here are some examples that do *almost* what you're trying to do.
Using strstr:
Code:
int count(const char * buff, const char * what)
{
int cnt = 0;
while((buff=strstr(buff,what))!=0) {
++cnt, buff++;
}
return cnt;
}
And using a more 'manual' approach.
Code:
int count(const char * buff, const char * what)
{
int cnt = 0;
int good = 0;
int i = 0;
int j = 0;
while(buff[i]!=0) {
if(good==0) { //reset
j=0;
}
else if(what[j]==0) { //got it
++cnt;
j=0;
}
if(buff[i]==what[j]) { //so far, so good
good=1;
}
else {
good=0;
}
++i, j++;
}
if(what[j]==0) {
++cnt;
}
return cnt;
}