How to use "strstr" to find all occurrences of a substring in a string not only first
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:
That function always returns 1.
int countPar(char str)
if (strstr(str, "par")!=NULL) // finds "par" in string
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.