This is my code that reads and searches for a particular word,
void* pthread_wordCounter(void* parameter){
int count = 0;
size_t linesize = 0;
char *linebuf = 0;
ssize_t linelenght=0;
static const char filename[]= "pg76.txt";
FILE *file = fopen(filename, "r"); //open file
if (file!=NULL){
while ((linelenght = getline(&linebuf, &linesize, file))>0) {
if (strstr(linebuf,"elephant")!=NULL) //finds if there is the word on the line
{
count++;
}
}
fclose(file); //close file
printf("The total amount of words is %d \n", count);
}
else{
perror(filename);
}
return 0;
}
How should I read only 1000 lines at a time (assuming the file has more than 1000 lines) and send this block of lines to another function that will search the word?