I have to count the appearances of a specific C string within a bigger one. I am using strstr() function to count and advance with a char pointer through the big C string. The problem is that it seems to count too little, like the reduction of the text is increasing to fast, jumping over big chunks of characters. I am using a type int variable, called 'x', to 'reduce' text from left to right, but I don't know were is the problem with assigning its new value.
int x=0;
while((p=strstr(text+x,triG))!=NULL)
{
v[i]++;
x+=x+3+(p-(text+x));
}
text is of type char*, dynamically alocated. triG is of type char[4], and p is of type char*.
textandtriGbesides the maximum lenght oftriG? Do you need to find for example all occurrences of "aaa" in "aaaaaaaaaa"? ;-)