Quote:
|
Originally Posted by conbrio
I was sort of surprised there wasn't a function in C's libraries to deal with this..
|
Here is another way to count the number of occurrences without using strtok()
int main()
{
char str[] = "HelloHelloHello";
int counter = 0;
char*ptr = strstr(str,"Hello");
while(ptr != 0)
{
counter++;
ptr = strstr(ptr+1,"Hello");
}
printf("counter = %d\n",counter);
return 0;
}