Description: 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 createmultiple threads where each thread is responsible for one file to count the number of words appeared in the file and report the number of time each word appears in a global linked-list. The typical format to run the program with input parameters is as follows: ./wordcountfreq File_1 File_2 ... File_n 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, you need to use pthread create() to create multiple threads (one for each file). Each thread needs to count the number of words in its file and keeps tracks of how many times each word appears in all the files using a global linked-list, where each node represented a different word in any file. When a thread finishes, it should print out the number of words it found as follows: Thread x: number of words in File_x is XXX At the end, the main thread needs to get the number of words from each thread and report the total number of words found by all threads as well as frequency of each word in all files as follows: All n files have been counted and the total of xxx words found ! aaa appears XXX times bbb appears YYY times ... zzz appears MMM times Here, words should appear in the dictionary order in the report! 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.
-
Engineering 2022-05-15 19:04:59