Hi
I am making an mp3 database at the moment and i have run into some difficulty when passing down the array to a function. I can do it when i create the array globally as obviously this means i dont have to pass it down, but i want to learn how to do it properly - have only been learning for a few months so i am still getting used to it all.
here is my code
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define MAXLENGTH 50
#define MAXGENRE 15
#define MAXMP3FILES 100
#define MAXFILEPATH 400
#define COMMANDLENGTH 800
#define FILENAMELENGTH 400
// Global Variable //
typedef struct {
int durmin,dursec;
char title[MAXLENGTH]; // title=array, MAXLENGTH=size of array
char artist[MAXLENGTH];
char genre[MAXGENRE];
char filepath[MAXFILEPATH];
} musicfile; // struct is called musicfile
FILE* fp;
void addtracks (int mp3database[]);
//////////////////////////////////////////////////////////////////////////////////////
int main (void)
{
musicfile mp3database[MAXMP3FILES]; // this creates a array called mp3database which is the size of MAXMP3FILES, each element in the array has the struct called musicfile
int menuoption;
puts("please enter a menu choice - choose 1 lol");
scanf("%d",&menuoption);
switch(menuoption)
{
case 1: //Add a track
{
addtracks(mp3database);
break;
}
}// end switch
system("pause");
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////
void addtracks (int mp3database[])
{
printf("Please enter the song title: ");
fflush(stdin); //fflush to clear previous keyboard input
fgets(mp3database[0].title,(MAXLENGTH),stdin);
printf("Please enter the artist: ");
fflush(stdin);
fgets(mp3database[0].artist,(MAXLENGTH),stdin);
printf("Please enter the genre: ");
fflush(stdin);
fgets(mp3database[0].genre,(MAXGENRE),stdin);
printf("Please enter the duration - m ss: ");
scanf("%d %d",&mp3database[0].durmin,&mp3database[*header].dursec);
printf("Please enter the filepath: ");
fflush(stdin);
fgets(mp3database[0].filepath,(MAXFILEPATH),stdin);
}
//////////////////////////////////////////////////////////////////////////////////////
Current errors i have been getting are
passing arg 1 of add tracks from incompatible pointer type
Request for member 'title" in something not a structure of union
it does not recognise any of the parts of my typedef.. artist, genre e.t.c
any help really appreciated!!
Emily