C Pointer Activity

Overview

For this activity you will write a main function, an interface header file, and a function implementing the header file interface, that

  1. Reads one line of data with three '$' terminated fields on it.
  2. Converts, as necessary, the fields to an internal numeric format.
  3. Returns these values via reference parameters (e.g., pointers).
  4. 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
Example

W$1349$1.414$

The Activity

  1. Download the activity zip file c_pointers.zip.
  2. Unpack the zip file in an empty working directory. You should see the following skeleton files:
    1. 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 a recapitulation of the interface information in this activity description.
    2. read_data.c
      The implementation of the read_data.h interface.
    3. 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
  3. 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.
  4. 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 Linus and get an executable file named test_pointers which meets the activities specification.

Submission

  1. The directory in your repository for this activity is PointerActivity.
  2. Your submission must contain exactly four files.
  3. The four files must be named exactly the following: Makefile, main.c, read_data.h, read_data.c.

Grading (10 points)

Submission: Correct files submitted according to specification.
1  Make: make test_pointers compiles and links the executable without errors.
1  Make: Makefile is correct with respect to dependencies among the various source, object and executable files.
1  Program: test_pointers reads and prints data according to the specification.
1  Source: Correct interface defined in read_data.h.
1  Source: Correct implementation in read_data.c.
1  Source: Correct use of read_data function in main.c.
2  QualitySource files conform to standards of quality in structure,style, naming and documentation.