CSCI 112
Lab 2 - C Expressions
Objectives:
- Solve
a simple problem using your own C program.
Readings:
- Read
Chapters 1 and 2 in the Hanly/Koffman text.
Deliverables: (DUE BY THE END OF THE 3RD LAB!)
- Submittal
of your lab2.c and Makefile
files.
TO DO (for today's lab)
- Design
and Write a program to solve Programming Project #4 on page 103 (exactly on the same
page in 6th edition, but p. 91 in the 5th edition) of the Hanly/Koffman text.
-
Use
Linux I/O redirection to enter your temperature in Fahrenheit. Do not
prompt for these values to be entered from keyboard, instead read them in
from a data file using
scanf
in
your program code, and Input/Output redirection
operator provided by Linux (in the command line type (1) name of your
application, (2) "<"
sign and then (3) a name of your input data file). For more info on I/O
redirections see the WebRefs.
-
For
your input data file (name it
datain
), build a short file
including only one integer in its first line.
Suppose you wanted to convert 156 F. You would build a file that had the
following number in line one:
156
Make sure to call this file "datain" and save it
to the same directory where lab2.c
resides.
-
A
sample run of your program assuming "lab2" for the name of your
run image would look like the following:
$ lab2 < datain
- "<" operator will
re-direct standard input for scanf command from your keyboard (default
setting), to the file datain.
- A
sample output (printed out on the screen) should look like the following:
Thank
you for submitting temperature reading in Fahrenheit.
The
temperature in degrees Celsius = 68.889.
-
Note
that the output needs to consist of two separate lines, and that the
result of temperature conversion must be displayed with 3 digits after
the decimal point.
- The
automatic submittal script will expect your output to be formatted exactly
as shown above. Make sure that your program prints out properly formatted
output.
- You do
not need to submit a sample data file. I will provide a set of test data
files for the automatic script to use to test your program.
- Make
sure to test your program thoroughly.
- Do NOT
forget to document your code properly (start
using comments in your code!).
LAB 2 ENRICHMENT
- Try
using fscanf
in your C program, to do the reading of input data.
-
Note:
Make sure to close the input file after
you done with reading the data.
-
A
sample run of your program can now look like the following:
$ lab2
- Now,
there is no I/O redirection necessary
- Try
using the Linux I/O redirections to print the output not on your screen but
into a separate (e.g. "dataout") file.