CompOrg Fall 2001

Homework #1 - File Dump program in C

Due Date: Sunday, Sept 9th (by 11:59:59PM)

Assignment

Write a C program that gets the name of a file from the command line (as a command line argument to the program), reads in the file and outputs the contents of the file in hex and ASCII, with 8 bytes of the file printed on each line. The output format must match the description given below exactly!

Program Output Format:

Each line of output describes 8 bytes of the file. Each line should consist of 3 parts:

  1. First comes a 4 hex digit number that specifies the offset of the bytes shown (where in the file these bytes are found). This offset should be 0000 for the first line, 0008 for the next line, etc. This limits the file size to 64K bytes, since we would need more than 4 hex digits to represent an offset larger than 64K. You don't need to worry about files larger than 64K bytes in size.

  2. The hex value of each of the 8 bytes follows, with the first byte being the leftmost in the output. Each byte from the file should be represented by a 2 hex digit number. There must be a space following each byte value (each byte from the data file should be shown as 2 hex digits followed by a space).

  3. The ASCII character represented by each of the 8 bytes. Unprintable characters should be changed to the character '.', so that things like newlines or control characters found in the file show up as '.' in the output. You can assume that any byte whose value as an unsigned integer is less than 32 or greater than 127 is unprintable.

Example: the data file contains the following text:

Hi Dave.
This is a sample input file.

Note that there is a newline (ASCII code 0A) at the end of each line.

Here is the output of the program (the program is named mdump and the data file is names sample) :

> mdump sample
0000: 48 69 20 44 61 76 65 2E Hi Dave.
0008: 0A 54 68 69 73 20 69 73 .This is
0010: 20 61 20 73 61 6D 70 6C  a sampl
0018: 65 20 69 6E 70 75 74 20 e input
0020: 66 69 6C 65 2E 0A 00 00 file....
>

Some things you will need to know (if you don't know 'C')

Submitting

What you need to submit

You should submit your program (the source code for your program), along with a file named README that contains a description of the system you used for development (what kind of machine, what kind of operating system and compiler).

You must also include some sample output, specifically you must run your program on the the two files sample1 and sample2. To get these files you should right-click on the above hyperlinks and select "save as". If you simply view the files in your browser and then save them, you may lose part of the file contents (any byes that happen to have values that are ASCII control/formatting characters can get lost/changed by the browser).

To make sure that you are getting sample input files correctly, we include one sample along with the correct output:

Correct output for the sample data file testdata:

0000: 01 02 03 04 05 06 07 08 ........
0008: 31 32 33 34 35 36 37 38 12345678
0010: 61 62 63 64 65 66 67 68 abcdefgh
0018: 41 42 43 44 45 46 47 48 ABCDEFGH
0020: 21 40 23 24 25 5E 26 2A !@#$%^&*

How to submit

Projects must be submitted via email to comporg-submit@cs.rpi.edu. The subject line of the submission message should contain a single number indicating the project number (1 for HW1, 2 for HW2, etc.). You must include your files as attachments, feel free to send a zip-file or a tar file.

Don't send compiled code!

You can expect a return email indicating receipt of your project submission immediately. This receipt will include a list of all the files that were successfully extracted by the submission script - please look over the receipt carefully to make sure your submission worked.

Multiple Submissions: You can resubmit up to 10 times for each project, we will always grade the last submission received unless you tell us otherwise.

Grading

We will compile and run your programs using gcc on a Unix computer, so you should include only code that will work in this environment. Specifically, if you develop the code on a PC using Visual C++ or some fancy environment, you need to make sure that it can compile under Unix (or at least using gcc under Windows).

Part of your grade will also be based on the sample output you provide in your submission. Make sure you run your program on the two sample files, save the output of each to a file and submit these files!

Your grade will be determined according to the following formula:

Source Code compiles and produces correct output: 50%

Sample output correct: 30%

Source Code is readable (commenting, structure, neatness, etc.): 20%

You should note that you do get some credit for simply including correct output for the two sample files. This means two things:

Notes and Hints