From 4cad50e85bb9f5c7454178916eae9f97838cbe15 Mon Sep 17 00:00:00 2001 From: stitchy Date: Sat, 14 Oct 2023 16:57:09 -0700 Subject: [PATCH] Language Search Complete --- movies/csv_parser.c | 2 +- movies/input.c | 4 ++-- movies/movies.c | 44 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/movies/csv_parser.c b/movies/csv_parser.c index 8e0287d..f4947cb 100644 --- a/movies/csv_parser.c +++ b/movies/csv_parser.c @@ -85,7 +85,7 @@ struct csv* parse_line(char* line) { void print_movies(struct node* head) { if(!head) { - printf("You F'd up mate (print_movies)"); + printf("Yo F'd up mate (print_movies)"); return; } diff --git a/movies/input.c b/movies/input.c index a8125c7..0c9b6f9 100644 --- a/movies/input.c +++ b/movies/input.c @@ -6,14 +6,14 @@ int integer_input(char* val) { char *error = ""; do { - printf("\n%s\n%s",error, val); + printf("%s\n%s",error, val); fflush(stdout); char buf[128]; read(STDIN_FILENO, buf, 127); num = atoi(buf); - error = "Input Error, try again."; + error = "\nInput Error, try again."; } while(!num); diff --git a/movies/movies.c b/movies/movies.c index ccd8884..66f540e 100644 --- a/movies/movies.c +++ b/movies/movies.c @@ -1,5 +1,7 @@ #include "movies.h" +int haschanged = 0; + int main(int argc, char** argv) { if(argc < 2) { @@ -42,7 +44,7 @@ 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\n"); + printf("4. Exit from the program\n"); int option; do { @@ -52,13 +54,13 @@ int menu() { return option; } -int year_print(struct csv* data, void* val) { +void year_print(struct csv* data, void* val) { if(data->year != *(int*)val) - return 0; + return; printf("%s\n", data->title); - return 1; + haschanged = 1; } void movie_year(struct node* head) { @@ -67,10 +69,14 @@ void movie_year(struct node* head) { 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"); } @@ -80,8 +86,34 @@ void movie_rate(struct node* head) { } +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) { - printf("stub\n"); + 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"); }