The purpose of these questions is to have you use the UNIX system and environment.
(100 points) The purpose of this question is for you to build on your (or my) answer to program 1 to gain experience with poiinters and dynamic storage allocation.
Read from the standard input. The input is supposed to be a C program. You need not check that it is, in fact, a legal C program; your program should simply assume it is.
Write to the standard output. In the first 6 columns of each output line, print a line number followed by a period ".". Print the input line beginning in column 9 (one tab from the left margin).
If the line is a preprocessor control line, and the preprocessor directive is define, add the name, line number on which the define occurs, and definition to a table. When the input is finished, print the table, headed by the title "Table of Defines" and beginning on a separate page.
Put the entries into an array, one definition and one name per entry. (So, you will have to use a structure for this.) The form of each entry is
struct defent { char *name; char *defn; };You must allocate space for the name and defn fields, but you may assume that no more than 1000 symbols will be defined.
#define PI 3.14159 #define E 2.71828 int main(void) { printf("pi = %f, e = %f\n", PI, E); }
1. #define PI 3.14159 2. #define E 2.71828 3. 4. int main(void) 5. { 6. printf("pi = %f, e = %f\n", PI, E); 7. } Table of Defines: name line definition PI 1 3.14159 E 2 2.71828
Modify your answer so that there can be any number of symbols, not simply 1000.
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562