View Single Post
Old Jun 29th, 2005, 8:39 PM   #3
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 532
Rep Power: 4 Ancient Dragon is on a distinguished road
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;

}
Ancient Dragon is offline   Reply With Quote