Music database using Linked Data Structures. halp!

This is a discussion on Music database using Linked Data Structures. halp! within the C Programming forums, part of the General Programming Boards category; So im trying to get a program to read from a text file that contains artists, albums and songs and ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    27

    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';
    }
    Last edited by Chucker; 03-28-2012 at 02:52 PM.

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    27
    I made three structures because the project came with a visual representation which used different color connecting boxes to base your code design off of (flow chart?). There are three red bubbles which are supposed to represent three different structure types and then each of them have different data type bubbles (artist, disc, song).

    The program is supposed to support three types of queries by the user, should be able to request and display the entire music database , listing of all songs by given artist and organized by disc name and track number. or display all tracks on a given disc.

    So i assume because the requests can be pretty specific, thats why there must be three

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 09-14-2010, 04:24 PM
  2. Replies: 8
    Last Post: 12-05-2008, 01:18 AM
  3. Structures within structures for a database
    By Holtzy in forum C Programming
    Replies: 2
    Last Post: 04-30-2008, 07:06 AM
  4. Replies: 2
    Last Post: 06-16-2005, 10:03 AM
  5. Ned Halp Wit Getng Input
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 03-18-2005, 02:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21