Your program must meet the following requirements:
1. Define a structure type to represent a single CD. The year must be stored as an integer, all other fields should be strings. Because memory space will be an issue you may not assume a length for the string fields, but must dynamically allocate appropriately sized strings as needed.
2. Write a function that takes a CD handle (i.e., a pointer to a pointer) and a file pointer as arguments. The file pointer should point to a file of CDs formatted as described above. The function should do the following (not necessarily in this order):
- allocate a CD for the handle to refer to
- read the next line from the specified file pointer using fgets
- use strtok and sscanf to parse the input line into the CD fields
As mentioned above, you must dynamically allocate the string fields in the CD to be exactly large enough to hold the corresponding strings. You may assume that an input line is at most 256 characters.
The function should return 0 if successful, 1 if an error occurred in parsing the line, and EOF if end-of-file was encountered.
3. Write a function that takes a CD handle argument. The function should deallocate all dynamically allocated memory associated with the CD (including the CD itself). The CD address should be set to NULL.
4. Write a function that takes a CD argument and prints out the CD to stdout in the following format (using the first CD in cds.db as an example):
The CD Astral Weeks was released by Morrison, Van in 1968 on Warner Bros.
page 1 of 2
5. Write a function that takes takes two arguments: a CD and the name of an artist. The function should return whether or not the specified CD was recorded by the indicated artist.
6. Now write a main function that takes two command-line arguments: the name of the input CD file and the name of an artist. Your main should do the following:
a. Open the indicated CD input file for reading.
b. Repeat the following for all CDs in the input file (i.e., until EOF is encountered in the
first step):
i. Use your function 2 to dynamically allocate and read-in a single CD. If your function indicates that an error has occurred in reading the CD then output an error message and exit the program.
ii. Use your function 5 to check if the CD was recorded by the artist indicated in the second command-line argument. If it was, print-out the CD using your function 4.
iii. Deallocate the CD using your function 3.