Get a copy of the animal guessing game program that I showed you yesterday in class: getcopy animal_game and getcopy animal.dat. Run the program by typing animal_game. Your task in today's lab will be to write the program.
To get you started, I have written a template for you -- getcopy labs/lab10.c. Note that this file defines an animal_info structure as having two fields: a character and a string. The character indicates whether it is an information-gathering question like "Is it a big animal?" or a guess like "Is it a skunk?", and the string is the question or guess. The main function then declares the animal_tree as an array of animal_info structures.
Look at the function initialize. This function gets the information to store in the animal_tree from the file animal_dat. Specifically, the function reads the initial number at the beginning of the line, then uses this number as an index into animal_tree. It reads the character i or g, and stores it in the record (at that index) in the questiontype field. It reads the question and stores it in the record (at that index) in the question field. Be sure to take a look at animal.dat so that you can see the data that this function is processing.
When the initialize function is done, all of the information is in the array animal_tree, and you are ready to begin playing the game. I've written a diagram of the information that is stored in the array, with an indication of where it is stored. This diagram is available in my handout directory in the file animal_array.pic.
Your job is to write the following:
You are now ready to do Homework #10.