Roger L. Kraft

59000-01 - Programming Assignment 2

This assignment has three parts. The three parts are Programming Exercises 2.12, 2.14, and 2.15 from the end of Chapter 2 in the textbook (pages 69-70). Please download this zip file. Be sure to review the homework grading criteria. This assignment is due Thursday, February 12.

Part 1: Do Programming Exercise 2.12 on page 69 of the textbook. Put your solution is a file utmplib2.c. Also, write a program who3a.c that uses this new library. In a separate text file, answer the two questions asked at the end of problem 2.12.

Part 2: Do a slightly modified version of Programming Exercise 2.14 on page 70. Write a program who3b.c that modifies who3.c to print out all entries from the utmp file (like who1.c) and also prints all the fields from each utmp record. Also have who3b.c take an optional command line argument that overrides the default utmp file. Test your program on the system's wtmp file. In the zip file there is a sample output called who3b.txt (using utmp as the input file). Your output should look the same. Notice the headers at the tops of the columns (use the tab character, '\t', to get the columns to line up).

Part 3: Do a slightly modified version of Programming Exercise 2.15 on page 70 of the textbook. Modify cp1.c, and call it cp1a.c, so that it takes a command-line option -n that means "no clobber". This means that cp1a should not overwrite an existing file. Your program should have the command-line syntax
     cp1a [-n] src dest
If the -n option is used and dest already exists, then cp1a should print an appropriate error message and exit. If there is any other option on the command-line, then your program should print an appropriate usage message and exit.

Write a Makefile that builds your programs for the above three parts. Make sure your make file works correctly. I will compile your code using your make file. If it doesn't work, I won't be able to grade your assignment. (Use the make file that comes with the code from Chapter 2 as the starting point for writing your own make file.)

Turn in a zip file called CS59000Hw2Surname.zip (where Surname is your last name) containing your C programs who3a.c, utmplib2.c, who3b.c, cp1a.c, the textbook's program utmplib.c (for Part 2), your make file Makefile, and your text file with answers to the questions in problem 2.12.

This assignment is due Thursday, February 12.