Getting Started
There is no skeleton code for this assignment—you'll be creating
your fgrep.c file from scratch. However, we do provide some
simple test files and a Bash script (runtests) that will run the
tests shown in samples and report whether
the output and exit status were correct.
Getting the Starter Code
The test files for this lab is available on the server in the
directory /cs/cs105/labs/lab6-fgrep. The first step in the
assignment is to make your own copy of the code to work on. From
your home directory on the server, run the following commands:
mkdir -p ~/cs105
cd ~/cs105
cp -ai /cs/cs105/labs/lab6-fgrep .
cd lab6-fgrep
You will now have a directory named lab6-fgrep in your working
directory on the server, and a copy of the testing script and sample
search files.
examples- A directory containing all the code used in the I/O lecture, which you can refer to as you work on your
fgrepimplementation. There is aMakefilein this directory that you can use to compile the example code (typemake), and you can also refer to the source files for the examples to see how they work. fgrep.c- The file where you will write your code for this lab.
test1.txt,test2.txt, andtest3.txt- Files containing text that your
fgrepwill search through. Don't edit these files. (test3.txtin particular, has no newline character at the end of the file, and opening it in an editor might add one automatically. Usingcat,more, orlessto examine the contents is safe.) runtests- A script that uses your implementation of
fgrepto search for various strings in different files and compares the results with the same test of the standard systemfgrep.
Edit fgrep.c and Add Your Names
Start by editing fgrep.c with your chosen text editor (e.g., emacs, nano or vim), and add both partners' names to the file. You will be submitting your fgrep.c file for grading at the end of the lab.
Explore the Example Code
Three bonus files have been added to the examples directory, beyond what you saw in the I/O lecture. These files are:
rev.c- A filter that reverses the characters in each line of input. It shows how to use the C library function
getlineto read lines of arbitrary length. count.c- A filter that counts upwards (or downwards) from a given number. It show how to use the
getoptfunction to process command-line options. contains.c- A filter that checks whether the input contains a given string. It shows how to use the
strstrfunction to search for a substring within a string.
The page for the I/O lecture has more information about these programs, and you can refer to them as you work on your fgrep implementation. The hope is that you'll find them very useful as you work on wrting fgrep.
(When logged in, completion status appears here.)