CSE110 Spring 2001

Homework #8 Hints


  1. No hints are available for this problem.
  2. No hints are available for this problem.
  3. One of the tricky parts of this problem is capturing the string argument of the g action. One way of doing this it to do two calls to getchar as usual, one to capture the action, and one that may capture either a newline or a space. Then, in the switch statement, if the action is a g the use scanf to get the string representing the object the user wants to grab - the right call to scanf to get a line is in the lecture notes. Remember that you will need to allocate memory for an array, either by declaring an array variable or by using malloc, for scanf to store the line in). You will then need one more call to getchar to take care of the newline at the end (instead of using scanf, you could also use GetLine, which takes care of the newline for you).

    The other thing that might be tricky is checking whether the string the user inputs matches the string that names each game object in its ObjectDescription structure. The matching should be done so that the case the user uses doesn't matter. One way to do this is to use all lower (or all upper) case for naming the objects when you initialize your ObjectDescription structures. Then, run a loop to convert the case of the user's input to match. Alternatively, you could write a function that runs a loop to compare each string character by character, converting each pair of characters to lower case with tolower (defined by the ctype.h library) before you compare them.