#include "movies.h" int haschanged = 0; int main(int argc, char** argv) { if(argc < 2) { printf("Please Specify Filename\n"); return 64; } struct node* head = parse_csv(argv[1]); enum OPTIONS menu_select = 0; while(1) { menu_select = menu(); switch(menu_select) { case YEAR: movie_year(head); break; case RATE: movie_rate(head); break; case LANGUAGE: movie_lang(head); break; case EXIT: printf("Goodbye~\n"); return 0; default: printf("You naughty~ Pick a correct option next time.\n"); } } print_movies(head); return 0; } int menu() { printf("1. Show movies released in the specified year\n"); printf("2. Show highest rated movie for each year\n"); printf("3. Show the title and year of release of all movies in a specific language\n"); printf("4. Exit from the program\n"); int option; do { option = integer_input("Enter a choice from 1 to 4: "); } while(option > 4 || option < 1); return option; } void year_print(struct csv* data, void* val) { if(data->year != *(int*)val) return; printf("%s\n", data->title); haschanged = 1; } void movie_year(struct node* head) { void* f = &year_print; int* val = malloc(sizeof(int)); *val = integer_input("Enter year to search movies from: "); haschanged = 0; iterate_nodes(head, f, val); if(!haschanged) { printf("No data about movies released in the year %d", *val); } printf("\n\n"); } void movie_rate(struct node* head) { printf("stub\n"); } void lang_print(struct csv* data, void* val) { for(int i = 0; i < data->numlang; i++) { if(!strcmp(val, data->languages[i])) { printf("%d %s\n", data->year, data->title); haschanged = 1; } } } void movie_lang(struct node* head) { void* f = &lang_print; char val[41]; printf("Enter Language to search for: "); fflush(stdout); fgets(val, 40, stdin); // Replace newline character with the null terminator val[strlen(val)-1] = '\0'; haschanged = 0; iterate_nodes(head, f, &val); if(!haschanged) printf("No data about movies released in %s\n", val); printf("\n"); }