Question
Suppose we want to store the information in a music library (a library of CDs) in CSV format. The following information is needed for each CD: , , , , , For example: Pink Floyd, Dark Side of the Moon, 1976, classic Rock, 5.0, Paul Watta (a) Post information for 5 CDs on the discussion board. A master list will be created. Use that master list in the following. (b) Read in the master list and parse each line. Store the parsed information in a CD database composed of appropriate matrices or arrays; for example: char cdDB_artist [MAX_NUM_CD] [MAX_STR_LEN]; char cdDB_title [MAX_NUM_CD] [MAX_STR_LEN]; int cdDB_year [MAX_NUM_CD] etc. (c) Allow the user to query the list by artist, title, year, genre, rating, or fan. Print the query and all the matching results to a file.
Explanation / Answer
#include #include #include #define MAX_NUM_LINES 400 #define MAX_STR_LEN 200 int readCDdata(char fileName[], char cvsMatrix[][MAX_STR_LEN]) { int i, count; count = 0; FILE *fp; fp = fopen(fileName, "r"); for(i = 0; i < 369; i++) { fgets(cvsMatrix[i], MAX_STR_LEN, fp); count++; } return (count); } void stripNewLineAtEOS(char str[]) { int n; n = strlen(str); if(str[n] == ' ') str[n] = ''; } int getCommaIndex(char str[], int index[]) { int i, counter; i = 0; counter = 0; while(i