Trying to scanf to a struct, but when compiling, I am given: 'request for member 'track' in something not a structure or union.
I have looked around on the internet and one suggestion was to replace the '.' with '->', which did not help. I have a feeling it is to do with where and how I have placed the struct, as example codes seem to place them in a different 'main'. Also, I am unsure if I should be entering an array number into the 'scanf' if there is an 'if statement' specifically for array entry.
Thank you! I hope what I have asked makes sense.
Here is the code, excluding the majority of the switch statement:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <windows.h>//for changing colour
struct song //creates a struct called song
{
char track[20];
char trackname[20];
char artist[20];
char genre[20];
};
int main(void)
{
system("color f5");//gives the window a white background (f) and purple text (5)
int menu, option, playchoice;
char song[20];
printf("Make a selection\n\n");
printf("1=Play\n");
printf("2=Music\n");
printf("3=Manage\n");
printf("4=Four\n");
printf("5=Quit\n");
scanf("%d", &menu );
switch( menu )
{
case 3:
int qtyadd;
printf("Number of tracks to add: \n\n");
scanf("%i", &qtyadd);
{
printf("Filepath for track to add: \n\n");
scanf("%s", song[1].track]; //references to the first record and its first variable
printf("Name of track: \n\n");
scanf("%s", songs[1].trackname);
printf("Artist: \n\n");
scanf("%s", songs[1].artist);
printf("Genre: \n\n");
scanf("%s", songs[1].genre);
}
for(i=0;i<qtyadd && i<99;i++)
struct song songs[99];
int i;
for(i=0;i<qtyadd && i<99;i++) ;
break;
}
system("pause");
}