C projects

Please send a ZIP file containing the solutions using the webpage https://homework.wmi.amu.edu.pl/sop (make sure to select the right task to submit). The page checks the contents of the ZIP file, so it should have the required file/files inside, otherwise the submission wil be rejected (it can have other files if needed). There is no deadline really: If you want a grade, please submit and drop me a note and I will grade it.

Do not throw your solution away after submitting it. If something happens (hopefully not) to my server, you may be required to send it again.

This tasks is not meant to be made in groups. If a solution is signed by more than one author, the score will be divided between them. You may be asked to defend your solution (you can be asked questions so I can be sure you really are the authors).

I know that for some of you the task is fairly easy, for some it will be very difficult. Overcoming these difficulties is very important in the learning process. Unfortunately sometimes you will be completely stuck. You may seek help from your fellow students, but it should come as hints, not solutions. Of curse you can also ask me for help.

Students from abroad may be surprised that such things have to be written here, unfortunately Polish students feel plagiarism often pays.

Plagiarism will not be tolerated and will be most severely punished. Failing the course (which is the obvious consequence) may be the least of your worries. I will not be conducting an investigation to find the true author: all offending solutions will be reported to the appropriate disciplinary commitee.

In my opinion the best way to learn programming is by scrathing one’s own itch. If you have an idea for a project you would rather write instead of the one described below, it may be possible for you to do that instead. The task below should be used as a model – you need to write a description of your project in a similar manner and have it accepted by me. I will not grade projects that were not agreed upon.

Task

(20 pt). Write in C (or C++) a simple clone of the cp utility

  1. When called with two arguments, the second of which is not an existing directory it should copy the first argument to the second (overwriting if necessary). (2 pt)
  2. When called with two arguments, the second of which is an existing directory, it should copy the first argument into the directory. (3 pt)
  3. When called with more than two arguments, it should copy all but the ultimate argument into the directory denoted by the last argument if it exists and print an error if there is no such directory. The more simple version is that it skips directories that are passed for copying (but see point g. below) (2 pt)
  4. With an option -i (interactive) it should ask before overwriting a file. (2 pt)
  5. With an option -n (no clobber) it should not overwrite files. (1 pt)
  6. With an option -f (force) it should overwrite files. This should be the default behaviour, so points are already in other items. (0 pt)
  7. With an option -r (recursive) the program should be able to recursively copy directories. (5 pt)
  8. Make sure that files in subdirectories are treated as they are treated by cp: if, say, dir1/file is being copied into dir2, then the new file is dir2/file, not dir2/dir1/file. But if we copied files recursively and dir1 was copied into dir2, then of course we end up with dir1/dir2/file.
  9. With -h the program should display some help and exit. (1 pt)
  10. With -v the program should display information about the author and exit. (1 pt)
  11. Any sequence of the options above may be given. The first of -h, -v takes precedence. If there are none of these, the last of the -i, -n, -f should have effect. (1 pt)
  12. Print relevant error messages to stderr. Errors should not be fatal (just skip offending files). (1 pt)
  13. Include a Makefile that builds your project. (1 pt)

Sample invocations

The order corresponds to the points above

Hints