CS60 Homework Assignment 8 ----------------------------- Due: Oct 24th at 1:00pm BMP Header Reader ------------------------ The task of this assignment is to write a simple program that takes a bmp image file as a commandline argument, reads the file's well defined header information, and finally displays the parts of the header individually for the user. The format of a valid bmp file's header can be found by following the link below or on the CS60 website: http://www.fastgraph.com/help/bmp_header_format.html Hints: ----------------- Chapter 3 in Stevens, Chapter 8 in K&R All of the header elements are <= 4 bytes, so the 'int' type is big enough to hold each element. Commandline arguments in C are handled as parameters passed to the 'main' function. Simply define your main as: int main(int argc, char **argv) { ... And any arguments given to the function on the shell command line will be passed to the main function. The first argument, argc, is simply the number of argmuents that were input by the user. The second argument, char **argv, is a list of strings (can also be specified 'char *argv[]' if you wish). Each argument is a string in argv, starting with the name of the executable itself. For instance, if my commandline was: ./hw8 foo.bmp la la goof Then in the program: argv[0] points to "./hw8" argv[1] points to "foo.bmp" argv[2] points to "la" argv[3] points to "la" argv[4] points to "goof" and of course argc is set to the value 5. Turnin -------------------- The turnin tag for this assignment is 'hw8' and must contain the code, a typescript showing the program compiling (with -ansi -pedantic) without warnings and running on at least 'mc6.bmp' and 'wut.bmp' from the webpage, and an optional README. Extra Credit -------------------- For 1pt extra credit, implement error checking in your program for the following scenarios: 1.) no file specified on the cmdline 2.) file does not exist/cannot be opened 3.) corrupt header (file < 54 bytes) Sample Output -------------------- [root@localhost hw8]# gcc -ansi -pedantic hw8.c -o hw8 [root@localhost hw8]# ./hw8 USAGE: ./hw8 [root@localhost hw8]# ./hw8 mc6.bmp Header Info for mc6.bmp ------------------ sig: 19778 sizefile: 864054 res1: 0 res2: 0 imgoffset: 54 sizehead: 40 width: 720 height: 400 numplanes: 1 bpp: 24 comptype: 0 sizedata: 864000 hres: 2834 vres: 2834 numcols: 0 numicols: 0 [root@localhost hw8]# ./hw8 wut.bmp Header Info for wut.bmp ------------------ sig: 19778 sizefile: 286194 res1: 0 res2: 0 imgoffset: 54 sizehead: 40 width: 334 height: 285 numplanes: 1 bpp: 24 comptype: 0 sizedata: 286140 hres: 2952 vres: 2952 numcols: 0 numicols: 0 [root@localhost hw8]# ./hw8 foo.bmp ERROR: corrupt img header [root@localhost hw8]# ./hw8 dur.bmp ERROR: cannot open file dur.bmp [root@localhost hw8]# ls *.bmp foo.bmp mc6.bmp wut.bmp [root@localhost hw8]#