How to use "strstr" to find all occurrences of a substring in a string not only first
Hello guys.
Im having troubles with the "strstr" function.
Im trying to count the number of times a substring appears in a string.
For this im using the STRSTR function but that function returns only the first occurrence of a substring in a string.
So if I use STRSTR to count the number of times the word "par" appears in "parparpar" it will return 1 because after the first occurrence, the function stops.
The code im using is this:
Code:
int countPar(char str[256])
{
int total;
if (strstr(str, "par")!=NULL) // finds "par" in string
total++;
return total;
}
That function always returns 1.
I want it to return 3 if I use "parparpar" as str.
All I want is to know the number of times a substring appears in a string.
THANKS!!!!!!