Hi,
Im doing an assignment that needs us to create a program to make a movie database.
In main() there is the structure array declarations, a main menu and 2 movie entries (so its not empty)
My main menu consists of a switch statement based on the user input.
From there it is passed to 1 of 3 functions that will either search database, add entry or print entire list of database.
Im having a hard time setting up my structure array and Im just looking for pointers of what I'm doing wrong.
the array is supposed to be able to fit 100 movies.
The code Im posting is only my global declarations, main and first function.
Whats happening right now:
-main menu works, hands to functions fine.
-passing to first function doesn't ask to enter anything
-initial 2 entries don't work and have error message "unused variable entry"
Code:
struct movie_list entry[size] = {{"Children of Men",109,8,"Science Fiction"}, {"Donnie Darko",133,6,"Science Fiction"}
any hints and pointers appreciated. Thanks!*edit* I'm using Eclipse and mingw
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define size 100 //Size of array defined
void enter_movie(void); //Prototypes for 3 functions
void print_movie(void);
void search_movie(void);
int counter;
struct movie_list { //Movie structure prototype
char title[30];
float length;
float rating;
char genre[20];
}entry[size];
int main(void)
{
int exit; //This variable is for the while controlling while loop. It breaks out the while loop to end the program
int menu; // variable for menu selection
struct movie_list entry[size] = {{"Children of Men",109,8,"Science Fiction"},
{"Donnie Darko",133,6,"Science Fiction"}
};
exit = 1; //sets parameter for while loop expectation to be met.
while(exit >=1){ //while loop to bring end of function operation below back to main menu
printf("The Movie List Builder V1.0\n\n");
printf("What would you like to do? \n Enter selection number between 1-4 below:\n");
printf("1: Add movie entry\n");
printf("2: Show entire movie list\n");
printf("3: Search for movie\n");
printf("4: Exit program\n");
scanf("%d", &menu);
switch(menu)
{ case 1 : //If user chooses 1 enter entry function is called
enter_movie();
break;
case 2 :
print_movie();//If user chooses 2 search movie function is called
break;
case 3 :
search_movie(); //If user chooses 3 print all entries function is called
break;
case 4 :
exit = 0; //If user chooses 4 the variable exit changes to 0 and the while loop ends.
//leads to program ending.
break;
default: //default if user doesn't input a number between 1-4
printf("\n Error:Selection is not between 1-4.");
break;
}} //end of while loop and switch statement
printf("Have a nice day!");
system("pause");
return 0;
} //main() end
void enter_movie (void) { //start of add entry function
int num;
printf("How many movies entries would you like to make?");
scanf ("%d" ,&num);
for (counter=2;counter>=num+2;counter++){
printf("Enter Movie Title:");
scanf(" %s",&entry[counter].title[30]);
printf("Enter Movie Length (in minutes):");
scanf(" %g",&entry[counter].length);
printf("Enter Movie Rating (Between 1-10):");
scanf(" %g",&entry[counter].rating);
printf("Enter Movie Genre:");
scanf(" %s",&entry[counter].genre[20]);
}
return;
} //End of add entry function