Lab 6: Fgrep
Introduction
In this lab, you'll be writing the C code for fgrep, a simple command that searches one or more files for a given string.
Starter Code and Instructions
Starter code
The starter code for this lab is already available on the server
in the directory /cs/cs105/labs/lab6-fgrep.
The first step is to get your own copy of the code to work on.
After logging into
wilkes, run the following commands:
mkdir -p ~/cs105 cd ~/cs105 cp -ai /cs/cs105/labs/lab6-fgrep . cd lab6-fgrep
Recall that this will cd into your cs105 working directory,
copy the starter code into a new directory called
lab6-fgrep and cd into that directory. Note that you'll be writing your
implementation in fgrep.c, which is mostly blank.
Example files
If you run ls, you'll see there is a subdirectory with a couple demo programs (with a Makefile to make them). As described in the writeup linked below,
- rev.c is a demo program that uses getline
- count.c is a demo program that uses getopt
Testing files
Along with the starter fgrep.c and the examples, you'll also see some testing files:
- test1.txt, test2.txt, and test3.txt: Files containing text that your fgrep will search through. Don't edit these files. (test3.txt in particular, has no newline character at the end of the file, and opening it in an editor might add one automatically. Using cat, more, or less to examine the contents is safe.)
- runtests: A script that uses your implementation of fgrep to search for various strings in different files and compares the results with the same test of the standard system fgrep.
Fgrep lab handout
Finally, here is the handout with the instructions for implementing fgrep.
Also, note that we introduced the Fgrep lab in lecture 20.
Due Date and Submission
Due: Friday December 4th, 1:15pm.
As described in the writeup, you should submit fgrep.c using the following command:
cs105submit -a 06 fgrep.c