Music database using Linked Data Structures. halp!
So im trying to get a program to read from a text file that contains artists, albums and songs and organize them alphabetically. also im trying to get it to allow to add new artists albums and songs and sort it. Just feel kinda lost atm with how to implement the find or insert functions
the text file for example is like this
Pink Floyd;The Wall;1979;1;In the Flesh?
Bruce Springsteen;Wrecking Ball;2012;7; ...
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define LINEBUFFERSIZE 256
/* Definitions for data structure nodes (artist, disc, track) */
struct song {
char *songName_p;
int trackNumber;
struct song *nextSong_p;
};
struct disc {
char *discName_p;
int year;
struct song *song_p;
struct disc *nextDisc_p;
};
struct artist {
char *artistName_p;9i
struct disc *disc_p;
struct artist *nextArtist_p;
};
typedef struct artist artist_t;
typedef struct disc disc_t;
typedef struct song song_t;
typedef struct artist *artistNodePtr;
typedef struct disc *discNodePtr;
typedef struct song *songNodePtr;
/* function prototypes */
artistNodePtr findOrInsertArtist( artistNodePtr *sPtr, char *artistID );
discNodePtr findOrInsertDisc(discNodePtr *sPtr, char *discID, int releaseYear);
void findOrInsertSong(songNodePtr *sPtr, char *songID, int trackID);
void getNextLine(char buffer[], int bufferSize, FILE *fptr);
/* May need more function prototypes here */
int main(int argc, char *argv[]) {
char lineBuffer[LINEBUFFERSIZE];
artistNodePtr startPtr = NULL;
FILE *musicFile;
char *artistTemp, *discTemp, *yearTemp, *trackTemp, *songTemp;
int year, track;
artistNodePtr theArtist;
discNodePtr theDisc;
if(argc==1) {
printf(" Must supply a file name as command line argument/n");
return 0;
}
if((musicFile = fopen(argv[1], "r")) == NULL) {
printf ("Error opening music file. Program terminated/n");
return 0;
}
getNextLine(lineBuffer, LINEBUFFERSIZE, musicFile);
while(!feof(musicFile)) {
*/
artistTemp = strtok(lineBuffer,";");
if (artistTemp == NULL) {
printf("Error analyzing input txt file; Program is terminated\n");
return 0;
}
discTemp = strtok(NULL ,";");
if (discTemp == NULL) {
printf("Error analyzing input txt file; Program is terminated\n");
return 0;
}
yearTemp = strtok(NULL ,";");
if (yearTemp == NULL) {
printf("Error analyzing input txt file; Program is terminated\n");
return 0;
}
trackTemp = strtok(NULL ,";");
if (trackTemp == NULL) {
printf("Error parsing input file; Program is terminated\n");
return 0;
}
songTemp = strtok(NULL ,"\n");
if (songTemp == NULL) {
printf("Error parsing input file; Program is terminated\n");
return 0;
}
/* convert the year and track strings to integers using the C atoi() function */
year = atoi(yearTemp);
track = atoi(trackTemp);
theArtist = findOrInsertArtist(&startPtr, artistTemp);
theDisc = findOrInsertDisc(&(theArtist->disc_p), discTemp, year);
findOrInsertSong(&(theDisc->song_p), songTemp, track);
getNextLine(lineBuffer, LINEBUFFERSIZE, musicFile);
}
/* database display code somewhere here */
}
artistNodePtr findOrInsertArtist( artistNodePtr *sPtr, char *artistID ) {
}
discNodePtr findOrInsertDisc( discNodePtr *sPtr, char *discID, int releaseYear) {
}
void findOrInsertSong(songNodePtr *sPtr, char *songID, int trackID) {
}
void getNextLine(char buffer[], int bufferSize, FILE *fptr) {
char temp;
int i = 0;
buffer[0] = fgetc(fptr);
while ( (!feof(fptr)) && (buffer[i] != '\n') && i<(bufferSize-1)) {
i = i +1;
buffer[i]=fgetc(fptr);
}
if ((i == (bufferSize-1)) && (buffer[i] != '\n')) {
temp = fgetc(fptr);
while (temp != '\n') {
temp = fgetc(fptr);
}
}
buffer[i] = '\0';
}