The purpose of the first project is to learn several language features of the American National Standards Institute (ANSI) C used for reading in information from stdin (standard input file, usually connected to the keyboard), manipulating pointers and accessing array elements. The project essentially deals with implementing a 2-dimensional character array that stores strings row-wise, and then doing some operations on that array.
Figure shows what a 2-dimensional array A[MAXROW][MAXCOL] looks like. We intend to hold n character strings S1, ..., Sn in an array like that, such that the first character of S1, is in A[0][0], and so on. Thus we want character j of string Si to be in A[i-1][j-1].
Note that a static layout of the array forces us to include not more than MAXROW strings, and each of them can not be of more than MAXCOL-1 length (since ANSI C strings are NULL-terminated).
To begin with we want to be able to perform the following operations on an array of this type:
After we have done that, we would like to modify the behavior of the system a bit, and add the following two capabilities:
What follows is a description of the major functions your ANSI C program should contain along with their necessary prototypes, usage information, pre-conditions and post-conditions.
The first function you have to implement in this project is a function that reads strings into a 2-D array of characters. The function should read a few strings from the stdin, each string terminated by a carrige return and the entire list of strings terminated by an End-of-File character (Ctrl-D).
The second function you have to implement in this project is a function that writes out the strings in a 2-D array of characters. The function should write out n specified strings in the first n rows of the array to stdout, each string beginning on a new line.
Once you have written read_array and write_array, debug the 2 functions using a trivial main program to make sure they work. Only then, proceed to the next function.
The third function you have to implement in this project is a function that
transposes the 2-D array of characters. The formula for transposing an
abstract two-dimensional array is:
Please note that you may not create another array to help you while transposing the array.
Having thus completed the first half of the project, we now move on to the second half. Please do not move on to this second half before you have gotten the first part to work correctly.
The fourth function you have to implement in this project is a function that creates a one-dimensional array of pointers to copies of the strings in the 2-D array of characters. To create the copies you must use dynamic allocation of memory and the string functions of ANSI C.
The fifth function you have to implement in this project is very similar to the second one. It should write out the strings pointed to by a 1-D vector array of character pointers. The function should write out the first n specified strings to stdout, each string beginning on a new line.
Your main function should create the necessary variables and then call the functions in sequence. It should first read in the 2-D array, then create the 1-D vector array, then write out the 1-D vector, then transpose the 2-D array and finally write out the 2-D array.
The code must be written and compiled in a modular fashion. There should be a file for each function, including the main function.
The set of files and file names must be:
The code should be clearly written. Each function should be well documented, both in the header file, and in the implementation file. The documentation should include pre- and post-conditions and appropriate comments on important aspects of the implementation.
The read_array and write_array functions are 30% of the grade, the function transpose_array is another 30% of the grade and the two *_vector functions are each 15% of the grade. This leaves 10% of the grade, which is given for the program structure.
The program is due Friday, September 11, at midnight. Penalities for unexcused late submissions are described in the syllabus.
The document submit.html (linked from the syllabus under the section Grading) contains a description of the submission procedure, which you should follow carefully.
This document was generated using the LaTeX2HTML translator Version 98.1 release (February 19th, 1998)
Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
The command line arguments were:
latex2html -no_subdir -split 0 -no_navigation writeup3.tex.
The translation was initiated by Erich Kaltofen on 2000-09-05