Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Primarily need help with the word frequency part of the code. I understand the forking and word counting, however I'm stumped when it comes to
Primarily need help with the word frequency part of the code. I understand the forking and word counting, however I'm stumped when it comes to creating the link list and couting the times each word appears in a file. Some code or breakdown of that portion would be much appreciated.
Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will create multiple processes with each process being responsible for one file to count its words and the number of time each word appears. The typical format to run the program with input parameters is as follows: /wordcountfreq File 1 File_2 Filen Details: First, the program needs to determine the number of files to be processed. This can be done with the argc parameter of the main function; Then, the argv parameter can be used to retrieve the name for each file. After that, fork) system call will be used to create multiple processes (one for each file). For each child process, it can simply invoke a function to count the number of words and how many times each word appears inside a specific file. You should use linked-list to count the number of times each word appears in the file. Each child process should print out the result like [Here, no inter-process communication is required as child processes will report (i.e., print out) their results individually]: Child process for File x: number of words is XXX aaa appears bbb appears XXX times YYY times zzz appears MMM times Here, words should appear in the dictionary order in the report! The main process should wait until all child processes report their results; then, the main process report the end of the program with the print out: All n files have been counted! For word counting, you could simply use the space character as the delimiter. Anything that are not separated by the space will be counted as a single word. For instance, the example "The first program is a Hello-world." will be reported as 6 words (where Hello-world is counted as a single word). You could compare your results using the wc utility that is available on Linux machines
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started