Where is the value that counts the words? Whats the meaning of
more
? What should
c
do for you?
WARNING - this snippet only works because the word
file doesnt overlap themselves:
int printRawData(const char *data, int length, int more)
{
int i,c;
printf(" -------------One Data Begins-------------\n");
for(c=i=0;i<length;)
{
if('f'!=data[i++]) continue; if(length<=i) break;
if('i'!=data[i++]) continue; if(length<=i) break;
if('l'!=data[i++]) continue; if(length<=i) break;
if('e'!=data[i++]) continue;
++c;
}
return c;
}
int _tmain(int argc, _TCHAR* argv[])
{
const char* text = "afile bfile filec file fixle files and so on file fil";
printf("%d",printRawData(text,strlen(text),1));
_gettch();
return 0;
}
Otherwise you should use a fast search like
Boyer-Moore.
Regards.