Here is what I have right now:
int findKey(char *in, char *key, int buf){
int count = 0;
FILE *f;
f = fopen(in,"r");
char temp[buf];
while(fgets(temp,buf,f) != NULL){
if((strstr(temp,key))!= NULL){
count++;
}
}
fclose(f);
return count;
}
I read through the txt file in, and look through it for key. If I find it then I increment count. However this seems only to work if there is only one occurance of key per like in the txt file. For example if the txt file is:
key Key key key
and char *key is "key" then count is only 1 but count should actually be 3. However if the txt file is:
key
key
Key
key
Then it returns the correct count (3). Not sure what's wrong here.