1 Checksum In this assignment you'll write a program that calculates the checksum for the text in a file. Your program w
Posted: Sun Jul 10, 2022 11:23 am
Note All of the test data files contain a termination character LF represented as a hexadecimal 'OA'. This character is included in all the checksum calculations. 1.2 Checksum size The checksum size is a single integer, passed as the second command line argument. The valid values are the size of the checksum, which can be either 8, 16, or 32 bits. Therefore, if the second 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: fprintf(stderr, "Valid checksum sizes are 8, 16, or 32\n"); The message should be sent to STDERR¹. 1.2.1 Format of the input file The input file specified as the first command line argument, will consist of the valid 8 bit ASCII characters normally associated with the average text file. This includes punctuation, numbers, special characters, and whitespace. 1.2.2 Output Format The program must output the following to the console (terminal) screen, also known as STDOUT: 1. Echo the text from the input file. 2. The echoed input text should be in rows of exactly 80 characters per row, except for the last row, which may possibly have fewer. These characters should correspond to the input text. 3. Print the checksum. • Remember to pad with X if the input data does not align with checksum size for the checksum calculation. For example, if calculating a 16 bit checksum, it could be necessary to add an additional X to arrive at an input file size of an even 16 bit size input. Likewise for 32 bits. However, note that it may be necessary to pad with 1, 2, or 3X characters for an even 32 bit size input. 4. The checksum line should be formatted as follows²: ¹Printing to STDERR can be accomplished using the following code:fprintf(stderr, normal printf format specifications); Java uses System.err.println(...); 2Where the variable checkSumSize is the checksum size of 8, 16, or 32, the variable checksum is the calculated checksum. Note that the checksums are masked to print the appropriate sizes such as two hex characters for 8 bits, 4 hex characters for the 16 bit checksum, and 8 hex characters for 32 bit checksum. The variable characterCnt is the character count of the input file and includes the terminating character LF or the hexadecimal value OA.
printf("%2d bit checksum is %81x for all %4d chars\n", checkSumSize, checksum, characterCnt);