CS 241 Data Organization using C
Lab 2: Testing Code and Working with Input Files


August 27, 2018

The purpose of lab today is to get you familiar with more code, learn more about testing your code, and playing reading in input from standard input.

1 Getting Started

Download the addNums.c file off the course webpage under the lab subdirectory. (Remember the linux command to do this from last lab?) You will also need the nums.txt file found in the same place.

To compile and run the code, use the following commands.

gcc -ansi -pedantic -Wall addNums.c  
./a.out < nums.txt

Here, the < command pipes the contents of a text file into standard in.

Notice that when the program prints numbers, those are printed on standard out. We can use the > command to pipe the output of our program from standard out into a text file.

We will be using both of these commands throughout the semester, so familiarize yourself with them now. If you accidentally write over a text file, you can re-download it from the server.

2 Adding to the code

3 Turning in your program

It’s ok not to finish this assignment – get through as many test cases as you can during the 50 minutes you have.

If you finish early, can you think of more test cases to add? The lab spec pointedly is missing at least one you will need.

Zip up your addNums.c file along with your test cases into a zip file entitled yourCSUsername.zip. You can use the following command for this:

zip yourCSUsername addNums.c testAddNums.in testAddNums.out

Then drop the zip file into the dropbox.