Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this recitation, you will write a program which will display the contents of a file in base-16 hexadecimal) and in ASCIL The skills that

image text in transcribed
In this recitation, you will write a program which will display the contents of a file in base-16 hexadecimal) and in ASCIL The skills that you will demonstrate: Ability to write a program Ability to access command line arguments Ability to read binary data from a file Ability to format output Complete the following tasks. You may receive guidance from your instructor or other students. All code that you submit should be written by you 1. Obtain the name of the input file from the command line. If the command-line is/hendump xxx.bin' then argv[1] will contain xocbin 2. Open thee for binary input 3. Print the entire file, 16-bytes per line. Each line should begin with an 8-digit hexadecimal offset into the file. This is the count of the bytes that you have already printed and therefore begins with 00000000. Each of the 16 bytes should be printed as a 2 digit hexadecimal value separated by spaces. Print leading zeros if necessary to ensure 2 digits. After all 16 bytes are printed display any values which are printable as ASCII characters, and display any non-printable values as Therefore there will be 16 symbols at the end of the line Some useful hints: 1. An integer can be printed in hexadecimal by using the format string "x"If you want to fix the width of the printed value.put the width before the xxx. If you want leading zeros to ensure all values have the same width,put a before this: 8x. This works for any number of digits. 2. To determine if a character is printable, include the header and use the sprint macro. This checks if the character in the variable is printable, and returns true or false 3. To print a value as a character, use the format string 4. To print alinefeed. add to your format string. If your print does not have this linefeed, then the next print will append to the current line. This is how you can print several values on a line in a loop 5. File I/O can be done using fopen and fread. Look at the man pages for these."man 3 fopen","man 3 fread" 6. You can check for end-of-file with feof. Requirements: Your program should be named "hexdump.c" without the quotes You should include your name and EUID in a comment at the top of the file . Your program will be graded largely on whether is works correctly on the CSE machines (eg, cse01. cse02 e 06) so you should make sure that your program compiles and runs correctly on one of these machines Sample Output (user input is in bold! d0044ce01-/sandbox hendump-Cyyy.bin 0001 45 46 46 01 1 1 0 0 0 0000 03 03 201 7 32 34 0 00002020 51 02 0 0 In this recitation, you will write a program which will display the contents of a file in base-16 hexadecimal) and in ASCIL The skills that you will demonstrate: Ability to write a program Ability to access command line arguments Ability to read binary data from a file Ability to format output Complete the following tasks. You may receive guidance from your instructor or other students. All code that you submit should be written by you 1. Obtain the name of the input file from the command line. If the command-line is/hendump xxx.bin' then argv[1] will contain xocbin 2. Open thee for binary input 3. Print the entire file, 16-bytes per line. Each line should begin with an 8-digit hexadecimal offset into the file. This is the count of the bytes that you have already printed and therefore begins with 00000000. Each of the 16 bytes should be printed as a 2 digit hexadecimal value separated by spaces. Print leading zeros if necessary to ensure 2 digits. After all 16 bytes are printed display any values which are printable as ASCII characters, and display any non-printable values as Therefore there will be 16 symbols at the end of the line Some useful hints: 1. An integer can be printed in hexadecimal by using the format string "x"If you want to fix the width of the printed value.put the width before the xxx. If you want leading zeros to ensure all values have the same width,put a before this: 8x. This works for any number of digits. 2. To determine if a character is printable, include the header and use the sprint macro. This checks if the character in the variable is printable, and returns true or false 3. To print a value as a character, use the format string 4. To print alinefeed. add to your format string. If your print does not have this linefeed, then the next print will append to the current line. This is how you can print several values on a line in a loop 5. File I/O can be done using fopen and fread. Look at the man pages for these."man 3 fopen","man 3 fread" 6. You can check for end-of-file with feof. Requirements: Your program should be named "hexdump.c" without the quotes You should include your name and EUID in a comment at the top of the file . Your program will be graded largely on whether is works correctly on the CSE machines (eg, cse01. cse02 e 06) so you should make sure that your program compiles and runs correctly on one of these machines Sample Output (user input is in bold! d0044ce01-/sandbox hendump-Cyyy.bin 0001 45 46 46 01 1 1 0 0 0 0000 03 03 201 7 32 34 0 00002020 51 02 0 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions