Question: C Programming __________________________ input_file_1.txt The first program is a Hello-world. __________________________________ input_file_2.txt The second file has Hello world. The followings are words, too: 4344 55^^%%

C Programming

C Programming __________________________ input_file_1.txt The first program is a Hello-world. __________________________________ input_file_2.txtThe second file has Hello world. The followings are words, too: 4344

__________________________

input_file_1.txt

The first program is a Hello-world.

__________________________________

input_file_2.txt

The second file has Hello world. The followings are words, too: 4344 55^^%% &&&

____________________________________

makefile

CC = gcc CFLAGS = -Wall -g

all: wordcount

clean: rm -f *.o wordcount

wordcount: wordcount.c $(CC) $(CFLAGS) wordcount.c -o wordcount

____________________________________________

word count.c

/*

* File: wordcount.c

* YOUR NAME ... YOU NEED TO IMPLEMENT THE FUNCTIONS HERE....

*

* ....

*/

#include

#include

// include other standard header files needed

// if you like copy your myio.h and myio.c here and use it when reading lines from a file!

// #include "myio.h"

/*

* YOUR COMMENTS

*/

int main(int argc, char *arvg[])

{

// YOU NEED TO IMPLEMENT THIS + some other functions!

return 0;

}

Overview This assignment is about process Process Creation and File Operations. You will write a program (say, wordcount.c) to find out the number of words 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 ils words. The typical format to run the program with input parameters is as follows: ./wordcount Filo_1 Pile_2 ... File_n Click here for a zip file containing template wordcount.c, makefile, and sample input files). count the number of words in each file. Details The wordcount program gets the file names as command line arguments. It then creates n = argc - 1 child processes using fork() in a loop and expects each child process Basically, you need to first implement the the following code segment in wordcount.c. for(i=1; i After fork() system call, parent continues and creates another child process while each child process simply invokes a function to count the number of words inside the given file argv[i]. (see the note below for more information about word counting). If the given file exists, the child process counds the words, prints out the count, and returns 0; or exit(0); indicating sucess. If the file does not exist, it prints an error message and returns 1; or exit(1); indicating an error happened. Here is a sample output (note one child may finish before the other child so your output lines may be in different order) also for cach child print actual pid and filename instead of pid_x Filc_x below: child process pid_1 for Pile_1: number of words is ... child process pid_2 for Pile_2: does not exists Child process pid_n for Pile_n: number of words is ... Note that, no inter-process communication is required for child processes to send their count to the parent! They print their results individually, as shown above. However, by exiting with exit code 0 or 1, actually they respectively inform the parent if they were sucessful or not when opening file. The parent will know about these exit codes whet it waits for the child processes. So, after the above for-loop in the parent process, let parent have another loop to WAIT and GET EXIT code for each child using wait() system call. By INSPECTING the exit code for each child, parent can count how many child process were succesful and accordingly it counts that. When all child processes are waited, the parent prints that count to show how many files are counted successfully and how many files did not exist. files So here is a sample output: Paren process created child processes to count words in ... files have been counted sucessfully! files did not exist NOTE: In your word counting function, you can read the file line-by-line by using a modified version of your ReadLine() function from previous assignment so that it can read a line from the given file without worrying about the length of the line. Then you can count the words in each line and sum them up. For word counting, simply use the following white-space characters: 'It', ' ', ' ' as the delimiter or you can use int isspace(char c) to check for white-space char. Anything that are not separated by the white-space characters (' ', 'It', ' ', ' ') will be counted as a single word. Make sure the spaces at the beginning or end of lines don't cause a problem. 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. Overview This assignment is about process Process Creation and File Operations. You will write a program (say, wordcount.c) to find out the number of words 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 ils words. The typical format to run the program with input parameters is as follows: ./wordcount Filo_1 Pile_2 ... File_n Click here for a zip file containing template wordcount.c, makefile, and sample input files). count the number of words in each file. Details The wordcount program gets the file names as command line arguments. It then creates n = argc - 1 child processes using fork() in a loop and expects each child process Basically, you need to first implement the the following code segment in wordcount.c. for(i=1; i After fork() system call, parent continues and creates another child process while each child process simply invokes a function to count the number of words inside the given file argv[i]. (see the note below for more information about word counting). If the given file exists, the child process counds the words, prints out the count, and returns 0; or exit(0); indicating sucess. If the file does not exist, it prints an error message and returns 1; or exit(1); indicating an error happened. Here is a sample output (note one child may finish before the other child so your output lines may be in different order) also for cach child print actual pid and filename instead of pid_x Filc_x below: child process pid_1 for Pile_1: number of words is ... child process pid_2 for Pile_2: does not exists Child process pid_n for Pile_n: number of words is ... Note that, no inter-process communication is required for child processes to send their count to the parent! They print their results individually, as shown above. However, by exiting with exit code 0 or 1, actually they respectively inform the parent if they were sucessful or not when opening file. The parent will know about these exit codes whet it waits for the child processes. So, after the above for-loop in the parent process, let parent have another loop to WAIT and GET EXIT code for each child using wait() system call. By INSPECTING the exit code for each child, parent can count how many child process were succesful and accordingly it counts that. When all child processes are waited, the parent prints that count to show how many files are counted successfully and how many files did not exist. files So here is a sample output: Paren process created child processes to count words in ... files have been counted sucessfully! files did not exist NOTE: In your word counting function, you can read the file line-by-line by using a modified version of your ReadLine() function from previous assignment so that it can read a line from the given file without worrying about the length of the line. Then you can count the words in each line and sum them up. For word counting, simply use the following white-space characters: 'It', ' ', ' ' as the delimiter or you can use int isspace(char c) to check for white-space char. Anything that are not separated by the white-space characters (' ', 'It', ' ', ' ') will be counted as a single word. Make sure the spaces at the beginning or end of lines don't cause a problem. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!