WSU Tri-Cities CptS 360 (Spring, 2022)

Lab 1: Comparing Files

This lab will introduce you to system programming by having you write a little utility program, compare_files, to compare any two files on the system.

This page will be available as

http://www.tricity.wsu.edu/~bobl/cpts360/lab01_compare_files/writeup.html

All the files you need are in a tarball, compare_files.tgz. If you're in a CSLab system, this is in the same directory:

http://www.tricity.wsu.edu/~bobl/cpts360/lab01_compare_files/compare_files.tgz

Extract the contents (with "tar -xvzf compare_files.tgz") and you will find these files in a directory named compare_files. You only need to modify one of them.

In what follows (and the rest of the course), pay particular attention to the manual page references. For example, fopen(3) refers to the Section 3 manual page for the function fopen() you get by entering:

$ man 3 fopen

in a bash(1) shell window. Pay attention to the SYNOPSIS section when calling the function.

main.c

This is the "driver" program. All it does is check the number of command line arguments and, if it finds two file names, calls compareFiles() on them.

Do not modify this file.

eprintf.h

This file provides the eprintf() and eprintf_fail() macros (not functions) that print error messages a la printf() to standard error and, in the latter case, exit. You do not need to use these (as main.c does), but feel free to do so in this and other assignments. They can make your code more readable.

Do not modify this file.

Makefile

This is an annotated makefile. It's all ready to use for this lab, but study it to learn how to construct a makefile in general for future labs and programming assignments.

Note that this file compiles all C code with these flags:

-g -Wall -Wstrict-prototypes

which should generate no errors or warnings. (A few points will be taken off for warnings and major, if not all, points will be taken off for compiler errors.) This will be a standard for the course.

Note also that this file links all object (*.o) files with the -g flag to enable source code debugging.

Do not modify this file.

compare_files.h

This is the header file for the compare_files() function. It contains the function prototype:

// These cpp directives ensure that the contents of this file won't be
// included more than once. Although they're not necessary here, this
// is a good practice to follow with all header ("*.h") files.
#ifndef COMPARE_FILES_INCLUDED
#define COMPARE_FILES_INCLUDED

int compareFiles(char *fname0, char *fname1);

#endif // COMPARE_FILES_INCLUDED

Do not modify this file.

compare_files.c

This is the file you need to modify for this lab. Follow the directions given in comments.

Note that the name of the program is compare_files, which is compiled using the source code file compare_files.c, which contains code for the function compareFiles(). There is nothing wrong with this.

Submission

Put all source files in a tarball built and named as directed in the course syllabus and submit it via Canvas.