Passing arrays of pointers into functions
Hello again everyone,
Still working on my program to store a list of mp3 details from a text file.
I've been writing a few functions to perform different operations on the stored information, such as; sort all the songs alphabetically by artist (using a bucket sort) and create playlists (using linked lists).
The mp3 info is stored in a structure like this:
The memory location of each SONG structure is then stored in an array of pointers, so that if I wanted to print the artist of track 1054 I could do this:
typedef struct mp3info
Now, if I wanted to do this within a function, I assumed I would do this:
printf ( "Artist: %s", array->artist );
This is just a simple example of the type of thing I'm having trouble with. Am I doing anything wrong when passing the array? If I try to print details from the array within the main function everything seems to work fine.
void printsong ( int tracknumber, SONG *array )
printf ( "Track: %d\n", tracknumber );
printf ( "Title: %s\n", array[tracknumber]->title );
printf ( "Artist: %s\n", array[tracknumber]->artist );
printf ( "Album: %s\n", array[tracknumber]->album );
printf ( "Genre: %s\n", array[tracknumber]->genre );
int main ( void )
SONG *array; //assume track details are already stored in array
/* Print track 3 */
tracknumber = 3;
printsong ( tracknumber, array );
Thanks for everyone who's helped me with this so far! Wouldn't have managed without all your help and advice!