C Language Program File Processing Paper
REMEMBER, THIS IS AN INDIVIDUAL ASSIGNMENT. YOU CANNOT WORK ON THIS WITH OTHER STUDENTS. DON’T LOOK AT ANY OTHER SOLUTIONS. IF YOU GET ANY HELP, REMEMBER TO COMMENT WHERE YOU GOT THE HELP IN YOUR CODE. WE WILL BE USING CODE COMPARISON TOOLS IN GRADING.
we are going to enhance the program we wrote for count the bits. we will create a program that counts the set bits in multiple files, and we will use all the CPU cores at our disposal to do it!
our new program, pbitcount, will take a list of files. for each of these files it will start a process to count the set bits in that file. this will allow us to count the set bits in parallel.
for example, if we run pbitcount with hi.txt and rand.dat twice, three processes will get created, and we get the following:
$ ./pbitcount hi.txt rand.dat rand.dat
the program will exit with a successful (0) exit code:
$ echo $?
there are two classes of errors you need to handle:
1) if the program is invoked with the wrong number of arguments, you should have an exit code of 1 and print the program name (how it was invoked) with the example usage statement:
USAGE: ./pbitcount filenames
$ echo $?
2) if the file cannot be accessed, you should have an exit code of 2 and use the perror() function to print an error message:
$ ./bitcount hi.txt filethatdoesnotexist.txt anothermissingfile.txt
filethatdoesnotexist.txt: No such file or directory
anothermissingfile.txt: No such file or directory
$ echo $?
when you implement your program, you will probably use the functions, fopen(), and fgetc(), so take a look at those. you must also use fork() to create processes and pipe() to communicate between processes.
your whole program must be implemented in a single file named pbitcount.c. make sure you compile with C (do not write a C++ program!).
submit your single pbitcount.c file.
|5||everything implemented in a single file|
|10||compiles without warning (cc –|
|10||passes given test cases|
|10||passes grader’s test cases|
|5||handles case when file does not exist or cannot be accessed|
|5||handles case when wrong number of arguments given|
|15||uses fork() correctly|
|15||uses pipe() correctly|
|25||code readability and logic|