C.I.S. 1.5

Brooklyn College

Professor Langsam

 

Assignment #5

 

Most operating systems provide data-compression utilities that reduce the size of text files so that they take up less room on the disk. These utilities work both ways; compressed files can be uncompressed later. Write a crunch program that reduces the size of C source files. Your program should remove all extraneous white space including newline characters. (You will have to research the meaning of extraneous, e.g. is a single blank required between tokens?). In addition, any comments should be discarded.

Your program should prompt you for the name of the file to be crunched, and should produce an output file that contains your crunched file

For example, if your program is called pgm.c the crunch program should produce a file called try­_me.c.

The code in try_me.c should compile with the same effects as pgm.c. Does it? Try your program on a number of your .c files. You should also report the reduction in space achieved by crunch, expressed as a percent. To accomplish this, write a simple routine cntchr that counts the number of characters in a file.

Submit your source code for both crunch.c and cntchr.c. Run these routines on the program you submitted for Assignment #1. Submit a copy of both the crunched and uncrunched version of Assignment #1 together with a sample output of the crunched version.