CIS 223
Assignment Number 4-S97
Pointers, Arrays, Structs, Argument Passing the C way
Templates in C (using void *)
Reading: This assignment is intended to help you review what we have
learned about the following topics:
- arrays and the use of arrays as function arguments;
- the use of structs and how to reference struct components;
- C argument passing mechanisms (dereferencing pointers, etc);
- achieving a kind of the C++ template in C through the use of
void * ;
- separation of concerns related to the design and implementation
of a server module vs the user or client module.
It is suggested that you:
- Read material on use of the qsort library function (attached to this
assignment).
- Read the Kernighan and Ritchie Appendix or Friedman/Koffman Appendixes
that contain information about the string.h library.
- Read about C I/O and C argument passing in any book on C that you
like (or in Kernighan and Ritchie).
Programming: (An individual project)
A. We have constructed a text file containing a collection of structs
each of which is made up of 4 fields:
- a symbol field containing a character string (max length of 6
characters, including the null character);
- a value field (integer) containing the numeric value of the field;
- a defined field, an enumerated type made up of two enumerators --
e.g.,
enum status {not_defined, defined}
- a used count field (integer) which contains a count of the number
of references to the symbol.
This information is stored on a file named sort.dat in the board
directory c223sxx. The board is made up of a character string of max
length 6 followed by three integers, but you are to treat one of the
integers as an enumerator value whenever you print the contents of a
struct. NOTE: The information stored in the file is actually part of the
symbol table generated by an assembler for a simple, hypothetical
assembly language program, but this is of no concern for this particular
problem.
You are to write a program which reads all of the symbol table entries
(all of the structs) into memory and sorts them using the qsort routine
in the C++ library. Your program should print the struct data as it is
read in and then reprint it after the sort. The information in each
struct should be printed on a single line (in four columns with
appropriate descriptive headers).
Turn In: Listing of a successful run of your program with the output
described above.
Due Date: To be determined.
B. Programming (also an individual project) -- Redo the Dice Simulation
Program using standard C argument passing and standard C I/O.
Turn In: Just the revised program and its output.
Due Date: To be determined.
CIS 223 Sample Data for Assignment 4-S97 (Part A ONLY):
LDAC
11
1
5
RNUM
41
1
2
SUM
898
1
3
LOOP
881
1
1
STAC
12
1
6
AVERAG
897
1
2
PNUM
42
1
2
ZERO
892
0
2
ONE
893
1
6
ADD
21
1
2
Return to Previous Page