Assignment 1 (10 Points) - Due Friday, September 07, 11:59PM

Announcements and Clarification

Sep 27: The testfiles and sample outputfiles. Assignment1_Testfile_Outputfile.tgz

Aug 27: You can find text files to test your program at the Project Gutenburg.
Aug 27: A draft Grading Rubric for Assignment 1 is available. Please note that minor changes to the grading rubric may be made during the grading process.

Whitespace Sequence Eliminator

Create a program capable of replacing all sequences of whitespace characters in a specified input text file with a single space character, writing the result to a specified output text file. A whitespace sequence is defined as any a sequence of consecutive characters that:

  1. Starts with a space or tab character.
  2. Ends with a space, tab, or newline character.
  3. Contains only spaces, tabs, or newlines within the sequence.

Note that a sequence of whitespace characters can span multiple lines. For example, if one line ends with a space and the following lines begins within a tab, this sequence of characters (space, newline, tab) are considered a whitespace sequence and should be replaced with a single space.

Commandline Arguments

Your program must be capable of utilizing a commandline argument to specify the input file.

spacer inputFile outputFile


Your program must ensure the user has correctly provided the required commandline arguments and display a usage statement if the provided arguments are incorrect.

Error Checking Requirements

Your program should check for all possible errors that may occur given the user specified files. The following provides a list of errors that you should check for and report.

  • Check to ensure the user has provided the required number of arguments.
  • Check to ensure that the both the input and output files can be opened. You should not assume that you can always write to an output file.
  • Ensure your program works correctly in even the input file is empty.

Distribution Files

The distribution files spacer.tgz for this assignment are based upon the simple spacer program discussed in lecture. The distribution includes a simple framework for using CMake. Please note that the requirements for your assignment differ from this distribution archive. Please consult the Assignments page for complete details on submission requirements and C coding style and standards requirements.

Given the provided distribution archive, the following commands can be used to extract, compile, and execute the example on ece3.ece.arizona.edu:

/usr/local/bin/tar xvzf spacer.tgz
cd spacer
mkdir build
cd build
cmake ..
make
./src/spacer