CSCI 1730 Programming Project 1A Fall 2008 File Padder This program is due by midnight on Thursday, June 11. The goal of this project is to introduce you to file I/O in UNIX. In this project you will implement a program that pads a file by inserting a specified unsigned integer (4 bytes) to it at the beginning. Write a C program that creates a copy of a binary file with an unsigned integer inserted at the beginning. Consider your design with a view to using buffering (which you will implement yourself) to make your program more efficient than it would be just reading and writing one byte at a time. Your program should take three command line parameters, where the first two are the names of files. The first parameter is the name of the input file and the second parameter is the name of the output file. The third parameter is an unsigned integer, specified in normal decimal format. So an example command line is: {odin} padder plainFile paddedFile pad_val Here padder is the name of your executable file and plainFile is the name of the input file. The padded version of the input file is to be written to paddedFile. The integer to pad by is specified by pad_val, which should be in the range 0 to 4294967295. (The latter is 2^32 - 1.) When your program finishes writing the output file, it should write to stdout as follows: plainFile sucessfully written to paddedFile after padding by pad_val where plainFile, paddedFile and pad_val echo the command line parameters. See Section E.4 of the C++ text for the use of command line arguments in a C program. There is also a small program illustrating this which is linked from the "projects" page. From the command line all parameters are strings, so the third parameter will need to be converted to an unsigned int. See 21.10 of the C++ text for conversion functions such as atoi( ) and atol( ) (string to int, string to long). The slides are 82--93 (available on WebCT.) You'll actually need to start with atol( ) since there is no library function for directly converting a string to an unsigned int. One change you should make is to use the header file , which is C style, instead of , which is for C++. Your project submission should include an implementation file padder.c, a Makefile and a READ_ME file. Your Makefile should compile padder.c to the executable file padder using gcc. Some things to note: *The names of the files must be followed exactly, so that the teaching assistant and the instructor can test your project without editing your code. *All file I/O must be done using the routines described in chapter 3 of the UNIX text. *You'll need to convert pad_val into an array of four bytes (unsigned char values) in order to perform the file I/O. This can be done by casting it. E.g., with pad_var (say) declared as an unsigned int, and pad_buf declared as unsigned char *, assign pad_buf = (unsigned char *) &pad_var. The bytes in pad_var can now be accessed as pad_buf[i] for i = 0, 1, 2, 3. *Your program must be written in C. *Test your padder program on text files, executable files, or any other sort of file you can find. Also try padding with different integers. *The program should be robust and include appropriate error checks. For instance, if paddedFile already exists then an error message should be issued; the existing file named plainFile should not be removed or altered. *The submission procedure and requirements common to all projects are described on a separate page which is linked from the course "projects" sub-page. Follow the submission procedure carefully. *A project which does not compile on odin using gcc for GCC 4.1.2 will score 0. Projects which do compile properly will be scored out of 100 (if on time) based on (1) correctness of operation, (2) quality of design, (3) coding style and documentation of the source code, and (4) correctness and usefulness of the READ_ME file and the Makefile.