Lab 8 - Structures and Pointers

Due - April 26/27, 2004

In this lab, you will write a program that uses structures and pointers. This program will open a file and read in information about a CD collection. The information will be stored in an array of structures. You should think very carefully about this lab 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 CD. The information stored in each structure should include the name of the artist and the name of the album.
  2. Declare an array to hold information for up to 50 albums. You can assume that the user will never have more than 50 CDs in her collection.
  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 CD in the collection. 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 CD. 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 collection. 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
Madonna
Like a Prayer
Talking Heads
Naked
Amos, Tori
Little Earthquakes

The first value represents the total number of CDs 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 artist and album for each entry.

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

  1. Make sure that each function is well documented.
  2. Make sure a lab assistant (Dianne or I) has seen your program run.
  3. 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