CS201
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 #3
on page 91 of the Hanly/Koffman text.
- Use Linux I/O redirection to enter your hours and minutes values. 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 two integers
in its first line.
Suppose you wanted to enter 12 hours and 30 minutes. You would
build a file that had the following numbers in line one.
12 30
Make sure to call this file "datain" and save it to
the same directory where lab2.c resides.
- Hint: What types of values are you going to use to derive t,
and then T? Integer, double or float? Note that you may need to convert
"30" minutes, to "0.5" of hour...
- 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:
Current temperature = 23.10
- 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