I am noob to working with typedef and and arrays. I need to pass them to a function that inputs the info in to the arrays from a file songData.txt. I am getting these errors but I am stuck. I am pretty sure there is something wrong with the data types from the errors but I just cant see what I am doing wrong and I cant make any more progress untill I get the file put in the parallel arrays.
Thanks in advance for any help!
Errors:
E:\Music\music.c(21) : error C2087: '<Unknown>' : missing subscript
E:\Music\music.c(25) : error C2087: '<Unknown>' : missing subscript
E:\Music\music.c(95) : error C2087: '<Unknown>' : missing subscript
E:\Music\music.c(96) : error C2055: expected formal parameter list, not a type list
E:\Music\music.c(102) : warning C4133: 'function' : incompatible types - from 'char [6]' to 'struct _iobuf *'
E:\Music\music.c(102) : warning C4133: 'function' : incompatible types - from 'int [1]' to 'const char *'
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMBER 4
#define ARRAYSIZE 15
// 0 1 2 3
typedef enum SongType {COUNTRY, DANCEPARTY, ELEVATOR, ROCK} SongType;
typedef int SongArray[ ];
void PrintMenu(int*);
void ReadMusicData(FILE*, SongArray[], SongType[]);
int main()
{
SongArray playList[ARRAYSIZE];
SongType song[ARRAYSIZE];
int seed, menuChoice=0;
FILE* inFile;
// opens the file for read only
inFile = fopen("songData.txt", "r");
// test to make sure file opens
if (!fopen("songData.txt", "r"))
{
printf("File Opening Failed!\n"
"Please ensure file is present and restart!\n");
//EXECUTION DONE, NEED TO ADD FLAG
}
seed = time(NULL);
srand(seed);
PrintMenu(&menuChoice);
printf("You chose %d\n", menuChoice);
ReadMusicData(inFile, playList, song);
return 0;
}
void PrintMenu(int *menuChoice)
{
printf ("*******************************************\n"
"WELCOME TO THE JLH05G MUSIC PLAYER!\n"
"********************************************\n\n"
"Please Choose a Menu Choice 1, 2, 3, or 4\n"
"1: Play Current Playlist In Order\n"
"2: Play Randomized Playlist\n"
"3: Play One Song\n"
"4: Leave the Program\n");
scanf("%d", menuChoice);
while ((*menuChoice < 1) || (*menuChoice > 4))
{
printf ("Please Choose a Menu Choice 1, 2, 3, or 4\n"
"1: Play Current Playlist In Order\n"
"2: Play Randomized Playlist\n"
"3: Play One Song\n"
"4: Leave the Program\n");
scanf("%d", menuChoice);
}
printf("You chose %d\n", *menuChoice);
return;
}
void ReadMusicData(FILE*, SongArray playList[], SongType song[])
{
int i, j;
char typeCode;
for(i=0; i<ARRAYSIZE; i++)
{
fscanf("%d %c", playList[i], typeCode);
switch (typeCode)
{
case 'C': song[j] = COUNTRY;
break;
case 'D': song[j] = DANCEPARTY;
break;
case 'E': song[j] = ELEVATOR;
break;
case 'R': song[j] = ROCK;
break;
}
}
}
songData.txt
Code:
1012 C
25 E
34567 R
987789 D
123 D
45320 D
555 R
123456 E
40506 R
111 E
13 R
12 C
1213 D
44444 R
19191 C
EDIT:found and fixed last bracket error and missing semicolon, reposted errors.
EDIT:removed square brackets from arrays in function call, reposted errors.
old function call = ReadMusicData(inFile, playList[], song[]);