C Pointer Activity


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 ):





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.

The Activity

  1. Download the activity journal and c_pointers.zip file 
  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 the read_data function prototype that you must update to match your modified function declaration.
    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 Linux and get an executable file named test_pointers which meets the activities specification.


  1. The directory in your repository for this activity is PointerActivity. Please place this directory in the root of your repository.
  2. The files  must be named  exactly the following: Makefile, main.c, read_data.h, read_data.c, ActivityJournal.txt.