I've made a program that takes information from a list of mp3s in a text file and stores them into a structure, which is then looked up using an array of pointers.
Each mp3 has the info: Track No - Title - Artist - Album - Genre
My program was working fine until tonight when I added a function that looks up all the different genres of music and displays a list of the genres to the user (I later want to allow the user to select one of these genres and have a playlist created with all the mp3s in this genre).
Now whenever I execute the program, it stops when it reaches the part when the new function is used, saying:
I tried to Debug, and it gave me this messageCode:lab1.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
Does anyone know what the problem might be?Code:Unhandled exception in mp3list.exe: 0xC0000005: Access violation
Here is the code I have written. The function that's causing the problem is the 'lookupgenres' function.
If anyone has any idea where I might be going wrong with this the help would be really appreciated!Code:/* A program to take information from a .txt file and store it in structures which can be looked up via an array of pointers */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <console_lib.h> #include <conio.h> typedef struct mp3info { char title[100]; char artist[100]; char album[100]; char genre[100]; } SONG; void lookupgenres ( SONG *array[20001] ) { typedef struct genrelist { char name[100]; struct genrelist *next; } GENRES; int tracknumber; GENRES genre; GENRES *current; int compare; int count; /* Check through all tracks for different genres */ for ( tracknumber = 1; tracknumber <= 100; tracknumber++ ) { /* Check to see if genre has been added */ /* If the genre list is empty, the check does not need to be made and the genre of the first track can be added to the list */ if ( genre.name == NULL ) strcpy ( genre.name, array[tracknumber]->genre ); else { compare = 1; current = &genre; compare = strcmp ( current->name, array[tracknumber]->genre ); while ( ( compare != 0 ) && ( current->next != NULL ) ) { current = current->next; compare = strcmp ( current->name, array[tracknumber]->genre ); } /* If the genre has not been added to the list, add it */ if ( compare != 0 ) { current = &genre; while ( current->next != NULL ) current = current->next; current->next = malloc ( sizeof ( GENRES ) ); current = current->next; strcpy ( current->name, array[tracknumber]->genre ); } } } current = &genre; for ( count = 1; count != 0 ; count++ ) { printf ( "%d - %s\n", count, current->name ); if ( current->next != NULL ) current = current->next; else count = 0; } } /* ------------------------------------------------------------------------ */ int main (void) { char string[500]; int tracknumber; SONG *current; SONG *array[20001]; /* Open file mp3list.txt for reading */ FILE *fp; fp = fopen ( "C:\\mp3list.txt", "r" ); while ( tracknumber < 100 ) { fgets ( string, 500, fp ); current = store ( string, &tracknumber ); array[tracknumber] = current; printf ( "%d - %s - %s - %s - %s", tracknumber, current->title, current->artist, current->album, current->genre ); } printf ( "Loading Complete!\n\n"); lookupgenres ( array ); return 0; }



LinkBack URL
About LinkBacks


