Lab 8 - Structures and File I/O

Due - December 6/7, 2004

In this lab, you will write a program that uses structures and reads from a file. This program will open a file and read in information about the inventory of a book store. The information will be stored in an array of structures. You should think very carefully about the design and implementation of this program because you will modify it and reuse pieces for Project 3.

Your program should do the following:
  1. Define a new structure type which will hold information about a single book. The information stored in each structure should include the title of the book, the author of the book, the isbn number of the book, the price of the book, and the number of copies of the book which remain in the inventory.
  2. Declare an array to hold information for up to 50 books. You can assume that there will never be more than 50 books in your bookstore.
  3. Write at least one function which will open a file (example file below) and read in and store (in the array of structures) information about each book in the inventory. Your program should prompt the user to enter the name of this file.
  4. Write at least one function which will iterate through the array of structures and print the information about each book. This function will serve as a test to ensure that all information was correctly stored.
  5. Write at least one function which will iterate through the array of structures and write all of the information to a new file. This function(s) will be used in Project 3 to write to a file any updates made to the bookstore. The output file should have the same structure as the input file. Your program should prompt the user for the name of the output file.

Hints

You can assume that a sample file looks like the following:

3
The Poisonwood Bible
Kingsolver, Barbara
0060930535
10.50
4
She's Come Undone
Lamb, Wally
0671021001
7.99
12
Snow Falling on Cedars
Guterson, David
067976402X
11.20
1

The first value represents the total number of books described in the file. After opening the file, you should read in this value and then implement a counting loop which will read in the information for each entry.

In order to read an entire line of text from a file, you can use the function fgets.

Due - December 6/7, 2004 - Beginning of Lab

Submit your completed algorithm and code. Note, your algorithm will be part of your grade.
  1. Make sure that each function is well documented. Your documentation should specify the type and role of the input paramaters and ouput.
  2. Copy and paste the output of your program to the bottom of your program itself. Make sure the output is a comment. That means, put a /* before the output and a */ after the output.

Sami Rollins