CEG220: Introduction to C
Programming for Engineers – I
Section 2
Final Project: Putting It
All Together
Program Background:
Frequently, you will have data files that have to be processed – but someone else wrote them in a tedious way that you find painfully annoying to deal with. Don’t get mad – get your computer to do the work for you; it’s good at repetitive tasks like this! There are little nifty utilities that most operating systems have that accomplish these frequently performed tasks.
Windows and DOS come with a variety of different commands to help you do what you need to do from a command line, but UNIX has more – much more (so many in fact that UNIX is the operating system of choice for many engineers). There are little utilities like cat (concatenate files), sed (pattern matching for search and replace), split (splits a file into multiple pieces), wc (counts the number of characters, words, sentences, and paragraphs in a file), and many more.
What’s really neat is that some of these tools can complement each other – you split a file into multiple pieces and need to put it together again, but the author of split neglected to implement the way to put everything together again. No problem! You can use cat to concatenate them together by specifying them on the command line. Let’s say we have a data file homework.zip that is 100 MB and needs to be split into 20 MB chunks. The user will type: split homework.zip 100 and will get 100 files: homework001.zip, homework002.zip, etc. You could then call: cat homework*.zip > homework.zip to reconstitute the file! The operating system will naturally expand the wildcard homework*.zip to create the list of homework001.zip through homework002.zip.
The command line to the left of angle bracket tells the operating system to perform the operation and take all of the outputs to stdout and dump them to the destination to the right of the angle bracket. This process is called piping.
Program Description:
Your task is to write a specification for a command line
utility that will take a file or list of files as an input, and dump its output
to stdout.
Any error messages reported should be sent to stderr (that way, the output of
your file doesn’t include the error message and instead tells the user what is
wrong). I would recommend an easy utility like cat or a program that filters all occurrences of a given string and
outputs the rest to stdout.
Program Requirements:
1) Your program must comply with the class programming standard
2) You must submit a hand-written program specification detailing (1) your approach to solving the problem, (2) the algorithm(s) you used, and (3) justifying the data types and loops you have used
3) You must utilize pointers and dynamic memory allocation when processing files. Static memory allocation is most often acceptable when the array will not need to change size; but since you can be dealing with files in the hundreds of bytes or in the hundreds of megabytes, you don’t want to allocate too much or too little memory. HINT: you can always seek to the end of the file, seek back to the beginning, and find the size of the file and allocate memory based on a function of the file size!
Grading Standard:
This project is worth 100 points. Please note that programs that do not compile or do not link will lose
all points related to run-time requirements (examples of run-time
requirements includes but is not limited to correct run output, handling
certain cases adequately, etc.). Grading standard will be followed
strictly:
50 points: Preparatory Requirements
· Compliance with class coding standard (18 points: 6 points each)
· adequate comments – clear, concise, useful; not excessive
· well-named identifiers
· follows program specification
· hand-written document / program specification (32 points)
· all algorithms designed properly and included in the spec
· all data structures are outlined
· purpose of the structure
· algorithms performed on the structure
· IF USING POINTERS: how and when the structure is deleted upon normal and abnormal termination of the program
· Uses pseudo-code to express the problem and how to solve it
100 points: Run-time Requirements
· Utilizes dynamic memory allocation (5 points)
· Deletes dynamically allocated memory upon normal/abnormal termination (10 points)
· Handles errors gracefully (5 points)
· Supports multiple input arguments and writes output to stdout (5 points)
· Performs the task in program specification (50 points)
· Good Error-handling (15 points)
· Run output (10 points)
Due Date:
This project is due on 11/19 at the beginning of class,
before you take the final exam. This
project will not be accepted late, barring an emergency.