Project 1: Warm-up Project
Questions about the project? Post them to our Piazza page.
Due: Monday, 9/17, by 9pm.
Before beginning: Read this tutorial. It has some useful tips for programming in the C environment.
This project must be done alone. You can talk to your colleagues about it, but every line of code must be written and understood by you. Copying code is considered cheating. Of course, you can always ask the TAs and professors for help too.
The first project is simply a warm-up to get you used to how this whole project thing will go. It also serves to get you into the mindset of a C programmer, something you will become quite familiar with over the next few months. Good luck!
You will write a simple sorting program. This program should be invoked as follows:
shell% ./zsort -i inputfile -o outputfile
The above line means the users typed in the name of the sorting program
Input files are generated by a program we give you called generate.c (good name, huh?).
Your goal: to build a sorting program called
shell% gcc -o generate generate.c -Wall
Note: you will also need the header file sort.h to compile this program.
Then you run it:
shell% ./generate -s 0 -n 100 -o /tmp/outfile
There are three flags to
The format of the file generated by the
Another useful tool is dump.c . This program can be used to
dump the contents of a file generated by
In your sorting program, you should just use
If you want to figure out how big the input file is before reading it in, use the
To sort the data, use any old sort that you'd like to use. You can even use
the library routine
To exit, call
If you don't know how to use these functions, use the man pages. For
Assumptions and Errors
32-bit integer range. You may assume that the keys are 32-bit integers, i.e. we will not test integers larger than 32 bits.
File length: You may not assume anything about the length of the file.
Invalid files: If the user specifies an input or output file that you cannot open (for whatever reason), the sort should EXACTLY print:
Too few or many arguments passed to program: If the user runs zsort without any arguments, or in some other way passes incorrect flags and such to zsort, print
Important: On any error code, you should print the error to the screen
This sorting assignment derives from a yearly competition to make the fastest disk-to-disk sort in the world. See the sort home page for details. If you look closely, you will see that your professor was once -- yes, wait for it -- the fastest sorter in the world.
Start small, and get things working incrementally. For example, first get a program that simply reads in the input file, one line at a time, and prints out what it reads in. Then, slowly add features and test them as you go.
Testing is critical. One great programmer I once knew said you have to write 5-10 lines of test code for every line of code you produce; testing your code to make sure it works is crucial. Write tests to see if your code handles all the cases you think it should. Be as comprehensive as you can be. Of course, when grading your projects, we will be. Thus, it is better if you find your bugs first, before we do.
Keep old versions around. Keep copies of older versions of your program
around, as you may introduce bugs and not be able to easily undo them. A
simple way to do this is to keep copies around, by explicitly making copies of
the file at various points during development. For example, let's say you get
a simple version of
Keep your source code in a private directory. An easy way to do this is
to log into your account and first change directories into
Handing It In
You should turn in TWO files. The first, containing your code, should be
so make sure it compiles in such a manner.
You should also include a file called
You should copy these two files into your handin directory. These will be
or more succinctly:shell% cp zsort.c ~cs537-2/handin/remzi/p1/ shell% cp README ~cs537-2/handin/remzi/p1/
(the copy utility knows that if the last thing specified is a directory, it should just copy the files into that directory and give them the same names. Read the man page for