This is an old revision of the document!
Corning Community College
CSCS1320 C/C++ Programming
~~TOC~~
To practice manipulating binary data in a C program (for fun and glory).
With the UNIX people exploring binary data, and using hex editors, it only makes sense to steer some of our activities towards the manipulation of binary data as well- one cannot effectively solve a whole domain of problems if they have no idea how to work with binary data.
This project aims to ameliorate that.
Binary data merely refers to data as the computer stores it. The computer is a binary device, so its raw data (as it exists on various forms of storage and media) is often referred to as binary data, to reflect the 1s and 0s being represented.
The data we have become familiar with is textual data. We read from and write to files with the express purpose of storing text in them. And with the use of various text processing tools, we can easily manipulate these text files.
But: did you know that all text data is also binary data?
The trick to remember is that its opposite is not always true: not all binary data is text. In fact most of it isn't. Text represents is a very narrow range of possible data values, and then only within a certain context. You may “see” random letters when viewing binary data, but there is no continuity. The data values that we utilize when interacting with text are also valid combinations of binary values. Which can mean almost anything.
So, text is really ONE (of many) possible representations of binary data. We need to gain a wider perspective and get more familiar with this more expansive and general notion of binary data.
The computer works in units of bytes, which these days means groups of 8-bits. C has the ability to arbitrarily read and write individual bytes of data, and we will want to make use of that to aid us in our current task.
Your task is to write a hex viewer and information highlighter, under the data theme of hard drive partition tables.
On lab46, in the cbf0/ subdirectory of the CPROG Public Directory, are a number of files ending in a .mbr; most are copies of Master Boot Records (MBRs) from various installed Operating Systems (so real, actual data).
Please copy these files into a working directory for your cbf0 endeavors. Assuming you have a ~/src/cprog/cbf0/ directory already existing and ready to go, you can run the following commands:
lab46:~$ cp /var/public/spring2016/cprog/cbf0/*.mbr ~/src/cprog/cbf0/ lab46:~$
If you get a prompt back (no errors), then you were likely successful. Change into your project directory and begin work.
Your task is to write a C program that takes a file name as a command-line argument, opens that file, reads its contents, and displays that data (in hex) to the screen according to various criteria:
Your program must:
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
$ submit cprog cbf0 cbf0.c cbf0.file /home/username/public_html/cbf0.jpg Submitting cprog project "cbf0": -> cbf0.c(OK) -> cbf0.file(OK) -> /home/username/public_html/cbf0.jpg(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.