Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a progamming assignment that is due on the 11th. I am required

ID: 643200 • Letter: I

Question

I need help with a progamming assignment that is due on the 11th. I am required to read a file "assign4.txt" using threads to split the task into 16 equally sized chunks. Each thread needs to calculate the word count of its chunk and then a main thread must read the total word count from consolidating all of the 16 smaller threads. These numbers must be outputted to the console. NOTE: The threads cannot split the file into multiple files. All lines of logic must be commented.

Must be programmed in C for use in a Linux operating envirionment.

Explanation / Answer

the program should be such that the reading of the txt file starts with a single process,

then each time the file is read there is a new thread created to read the file calculate the wordcount of the portion of the file read.

# include

# include

int size, wcarr[16], total-words =0;

char rdchar;

function wordcount(fp,i)

{ rdchar = getch(buff);

while rdchar <> NULL

{

  

   if rdchar == ' ' /* when ever a space occurs it means end of word - so check if end of word has come */

   then wcarr[i]++; /* add one to the word count of this particular portion of the file */

rdchar = getch(buff); /* read each character of the text stored in the buffer after the read statement */

} /* end of loop */

} /* end of function */

function findfilesize()

{

}

main() {


while !feof(fp) /* loop till end of file is reached */
{
for(i=0; i<16; i++) /* dividing program into 16 chunks */
fscanf (fp , "%s" ,buff ); /* read the contents into the variable buff*/

   fork(); /* create a new process */

wordcount(fp,i); /* that will call the function wordcount */

} /* end of while loop */

for (j=0;j<16;j++) /* loop to calculate the total of the word count performed by each fork */

{ total-words = total-words + wcarr[i] ; }

printf ("The total words in the file were %d ", total-words); /* print the total calculated */

} /* end of main */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote