0
This is my code that reads and searches a certain 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?
Edit the question and put the code you’ve already done to make it easier for us to understand your problem.
– DaviAragao
What does this have to do with thread?
– Maniero
In this context it does not have much to do, but can be applied to a multithreaded environment
– VLun
As tags should be used to identify your problem, not to say what you will one day do with it.
– Maniero
for(i=0; i<1000; i++){ lerlinha() }
?– hugomg