Homework 4: Intermediate C Programming

Due November 20, 1997

This assignment consists of one larger C programming exercise, which will increase your familiarity with basic C, and will also give you some debugging experience. Do the exercise below, and submit your code, together with a file HW4_WRITEUP, which describes how to run your program and gives a brief demonstration script. Your submission should also include a Makefile, which should permit us to compile your program simply by typing ``make.'' A basic discussion of ``make'' can be found in Section 11.17 of Kelley and Pohl. I have also placed online a tutorial on make, in Postscript form or ASCII text form.

The program you write for this exercise will probably be between 400 and 500 lines of C. Whereas last week's exercise could be done fairly easily using just arrays, for the new exercise you will probably find it advantageous to make full use of structures and pointers.


For this exercise, you will write an extremely simple, line-oriented text editor program, called view. When you start view, it enters command mode. In command mode, view prints a prompt and waits for you to enter a command line. When you enter a command line, view processes that command and then returns to command mode. There are nine commands, which have extremely simple formats: Your view program should work correctly no matter how long the lines are, in the files that are read in, or in the input supplied interactively by the user. This means that your program will have to allocate memory on the fly from the heap area. When your program is unable to allocate enough memory from the heap area, it should fail in a graceful manner.


Here is an example session with view. The ? character is view's prompt while in command mode. There is no prompt while view is in text mode. ? r test.txt 2 lines read. ? t The quick brown fox ? (ENTER typed here) jumped over the lazy dog. ? i with the shining eyes ^Z ? t with the shining eyes ? - The quick brown fox ? w test.txt 3 lines written.

Hints and Suggestions

Eugene W. Stark