You will write a C program that reads input from a file on
the disk (not from the keyboard!) and writes its output to a file on the
disk (not to the screen!).
You'll also continue working with functions, variables, input and output.
Under your cisc105 subdirectory, make a new directory for lab03, just like we did for lab02 last week (see last week's lab if you are not sure what to do).
Complete exercise 3.6 from your Tan and D'Orazio textbook, p. 163. Call your
program file lab03a.c.
First, it is recommended that you sketch out your program on paper. When you
are ready to type it in, cd into your ~/cisc105/lab03 directory, and use the
text editor to enter your program.
Note that this program does not use loops
or arrays (those are concepts covered in later chapters).
Each of the values a1, a2, etc, from lines 2 through 6 of the input
file should be stored in its own variable. You may reuse the same variables
a1, a2,
etc.
for
the
second
occurence
of these
numbers on lines 8 through 12.
To test your program you will need to use the text editor to create a data file called DISTANCE.DAT. That file should just contain numbers, in the format shown on page 164 of your text. You don't have to do anything special to this file other than create it with the text editor (for example, you don't have to compile it.) When you run your program, the program will open this file up and read data from it. Lesson 3.6 (starting on p. 120 of your text) explains how this works. Be sure that you use all capital letters for the name of this file, both when you create it with the editor, and when you put the file name in your program code.
The file DISTANCE.OUT is one you will not create with the editor. Instead, that file should appear in your directory when you run your executable program. Lesson 3.8 in your textbook (starting on p. 132) explains this in more detail.
To get full credit, be sure you look over the reading notes for chapter 3 (around Lesson 3.6 and Lesson 3.8) about using an if statement to check the result of opening a file for input or output.
Finishing up (and grading)
Make a script called lab03.txt. In this script, do the following steps. If you are unsure what to do, consult last week's lab for hints.
When you are done creating your script, print it (see previous labs for the print command), and submit lab03.txt and lab03a.c to WebCT.
Total: 100 pts