Assignment #1

Intermediate C Programming

UW Experimental College


Assignment #1

Handouts:

Syllabus
Assignment #1
Class Notes, Chapter 15
Game source code
Notes about ``The Game''

Review Questions:

  1. What are the four parts of a structure definition?
  2. What is p->m equivalent to?
  3. What's wrong with this code?
    	struct x *p = malloc(sizeof(struct x *));
    
  4. The last code example in chapter 15 of the notes reads lines from stdin and prints them back out in reverse order. What would happen if the prepend function did not call malloc and strcpy to allocate space for a new copy of each listnode's item, but instead simply set newnode->item = newword?

Exercises:

1. Get the initial version of the game (as handed out in class) to compile and run. It should print a ``?'' prompt, and you should be able to type the ``n'', ``s'', ``e'', and ``w'' commands to attempt to move around, and the ``take'' and ``drop'' commands to pick up and drop objects. (There are one or two other commands, which you can learn by studying the file commands.c.)

Study and understand as much of the source code of the game as you can.

2. Add a ``help'' command which prints a message listing the available verbs (or at least the most common ones).

3. Add a ``long description'' field to the object and room structures. (It can either be an array of char or a pointer to char.) Modify the initializations of the objects and rooms arrays in main.c to initialize the description field for some or all objects and rooms. Arrange that the ``look'' command print the long description of the current room (if it has one), and that the description is also printed when the actor enters a new room. Add an ``examine'' command which prints the long description of an object, if it has one. (Otherwise, have it print ``You see nothing special about the %s.'')



This page by Steve Summit // Copyright 1995-9 // mail feedback