For
this activity you will write a main function, an interface header file,
and a function implementing the header file interface, that
Reads
one line of data with three '$' terminated fields on it.
Converts,
as necessary, the fields to an internal numeric format.
Returns
these values via reference parameters (e.g., pointers).
Prints
the results.
Input Format
Your program will read exactly one line from standard input. The line will be formatted as follows (
you need not worry about any errors
):
C$I$D$
where
C
is a single character.
I
is a string of characters representing a legal decimal integer.
D
is a string of characters reprsenting a double precision number.
$
is the literal dollar sign character.
Examples
W$1349$1.414$ x$1234$3.14159$ T$98754$6.023$
All input lines may be assumed to be legal, and there are at most 25
characters in the strings for the integer and double precision number.
The
read_data
routine reads one line of data, consisting of three fields, and returns the values in the fields via reference parameters.
The calling sequence has three arguments: - a pointer to a char variable. - a pointer to an int variable.
- a pointer to a double precision variable.
The routine
1. Reads the three fields into local variables using
getchar()
-
DO NOT USE
scanf()
2. Converts the two numeric fields from ASCII strings to numbers:
a) Use atoi for the integer.
b) Use atof for the double.
3. Uses the parameter pointers to store the three values in variables
declared in the caller, and
4. Returns.
Unpack the zip file in an empty working directory. You should see the following skeleton files:
read_data.h
The interface to the function that reads the three values on the line,
converts the two numeric strings to integer and double precision,
respectively, and returns the three values via argument pointers of the
appropriate type. The header file has the read_data function prototype that
you must update to match your modified function declaration.
read_data.c
The implementation of the read_data.h interface.
main.c
The driver program which declares the variables filled in by the read_data
function, calls the function with appropriate pointer arguments, and,
on return, prints the results. The format string to use is given in the
header comment of main.c.
You
must
complete this activity by filling in the three skeleton files above. The point is
NOT
to print a character, integer and double precision number, rather, it
is to give you experience using pointers to pass data into and out of a function.
You are also to create a
Makefile
whose primary target is an executable program named
test_pointers
. This executable depends on the two object files, which in turn depend
on the approriate source files. Your instructor should be able to type
the command:
make test_pointers
on Linux and get an executable file named
test_pointers
which meets the activities specification.
Submission
The directory in your repository for this activity is
PointerActivity.
Please place this directory in the root of your repository.
The files
must
be named
exactly
the following:
Makefile,
main.c,
read_data.h,
read_data.c,
ActivityJournal.txt.