Question: In this assignment you'll write a program that calculates the checksum for the text in a file. Your program will take two command line parameters.

In this assignment you'll write a program that calculates the checksum for the text in a file. Your program will take two command line parameters. The first parameter will be the name of the input file for calculating the checksum. The second parameter will be for the size of the checksum (8, 16, or 32 bits). The program must generate output to the console (terminal) screen as specified below.

Command Line Parameters

Your program must compile and run from the command line.

The program executable must be named checksum (all lower case, no spaces or file

extension).

Input the required file names as command line parameters. Your program may NOT

prompt the user to enter the file names. The first parameter must be the name of the file used for calculating the checksum, as described below. The second parameter must be the size, in bits, of the checksum. The sample run command near the end of this document contains an example of how the parameters will be entered.

Your program should open the two files, echo the processed input to the screen, make the necessary calculations, and then output the ciphertext to the console (terminal) screen in the format described below.

Checksum size

The checksum size is a single integer, passed as the first command line argument. The valid values are the size of the checksum, which can be either 8, 16, or 32 bits. Therefore, if the first parameter is not one of the valid values, the program should advise the user that the value is incorrect with a message formatted as shown below:

printf("Valid checksum sizes are 8, 16, or 32 ");

The message should be sent to STDERR.

Format of the input file

The input file will consist of the valid ASCII characters associated with the average text file. This includes punctuation, numbers, special characters, and whitespace.

Output Format

The program must output the following to the console (terminal) screen:

Echo the input file

Print the checksum.

The echoed input text should be in rows of exactly 80 letters per row, except for the last row, which may possibly have fewer. These characters should correspond to the input text. The checksum line should be formatted as follows:

X bit checksum is Y for all ZZZ chars

Using the following:

printf("%2d bit checksum is %8lx for all %4d chars ", checkSumSize, checksum, characterCnt);

Where X is the checksum size of 8, 16, or 32 and the filename xyz.ext is the input filename and Z is the calculated checksum. Note that the checksums are masked to print the appropriate sizes such two hex characters for 8 bits, 4 hex characters for the 16 bit checksum, and 8 hex characters for 32 bit checksum.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!