From be78c1dbfaf5f22ec589a90258796daca67ab04d Mon Sep 17 00:00:00 2001 From: stitchy Date: Sun, 15 Oct 2023 16:11:39 -0700 Subject: [PATCH] Add comments and clean up --- movies/csv_parser.c | 3 +++ movies/input.h | 1 + movies/movies.c | 22 ++++++++-------------- movies/movies.h | 2 ++ movies/node.h | 5 +++++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/movies/csv_parser.c b/movies/csv_parser.c index f4947cb..7de5725 100644 --- a/movies/csv_parser.c +++ b/movies/csv_parser.c @@ -82,6 +82,7 @@ struct csv* parse_line(char* line) { return mov; } +// Debugging; not used void print_movies(struct node* head) { if(!head) { @@ -102,6 +103,7 @@ void print_movies(struct node* head) { } } +// Debugging; not used void print_line(struct csv* printer) { printf("%s, %i, ", printer->title, printer->year); @@ -112,6 +114,7 @@ void print_line(struct csv* printer) { } +// Counts number of times given char appears in string int count_char(char* text, char cha) { int length = strlen(text); diff --git a/movies/input.h b/movies/input.h index 83cc02d..a2d4906 100644 --- a/movies/input.h +++ b/movies/input.h @@ -6,6 +6,7 @@ #ifndef INPUT #define INPUT +// Error checking integer input int integer_input(char*); #endif diff --git a/movies/movies.c b/movies/movies.c index 852bb0e..4b70b38 100644 --- a/movies/movies.c +++ b/movies/movies.c @@ -11,6 +11,7 @@ int main(int argc, char** argv) { struct node* head = parse_csv(argv[1]); + // menu logic enum OPTIONS menu_select = 0; while(1) { @@ -32,11 +33,7 @@ int main(int argc, char** argv) { default: printf("You naughty~ Pick a correct option next time.\n"); } - } - print_movies(head); - - return 0; } int menu() { @@ -71,6 +68,7 @@ void movie_year(struct node* head) { *val = integer_input("Enter year to search movies from: "); haschanged = 0; + // Prints each node if movie year the same as specified iterate_nodes(head, f, val); if(!haschanged) { @@ -85,6 +83,7 @@ void lang_print(struct csv* data, void* val) { for(int i = 0; i < data->numlang; i++) { + // Prints if movie is in given language if(!strcmp(val, data->languages[i])) { printf("%d %s\n", data->year, data->title); haschanged = 1; @@ -118,8 +117,6 @@ void check_year(int* data, int* year) { if(*data == *year) haschanged = 1; - //printf("%d, %d\n",*data, *year); - } void find_year(struct csv* data, void* year) { @@ -127,30 +124,26 @@ void find_year(struct csv* data, void* year) { void* f = &check_year; haschanged = 0; + // Finds every year that has a movie produced in our list iterate_nodes(year, f, &data->year); - if(!haschanged) { + if(!haschanged) appendv_node(year, &data->year); - //printf("Change Val: %d\n", data->year); - } haschanged = 0; } -void print_node(int* val, char* garbage) { - - printf("%s\n", garbage); -} - void print_rating(struct csv* data, struct csv** val) { + // Null case handled here if(val[0] == NULL) { if(data->year == haschanged) val[0] = data; return; } + // Sets pointer to movie struct of new highest rating if(data->rating > val[0]->rating && data->year == haschanged) val[0] = data; @@ -166,6 +159,7 @@ void index_nodes(int* val, void* head) { void* f = &print_rating; + // Find the node of highest rating for specified year iterate_nodes(head, f, cur_val); printf("%d %2.1f %s\n", cur_val[0]->year, cur_val[0]->rating, cur_val[0]->title); diff --git a/movies/movies.h b/movies/movies.h index b76503b..ed2cd78 100644 --- a/movies/movies.h +++ b/movies/movies.h @@ -12,10 +12,12 @@ int menu(); +// Headers for the options called by menu void movie_year(struct node*); void movie_rate(struct node*); void movie_lang(struct node*); +// Menu Options enum OPTIONS { YEAR = 1, RATE = 2, diff --git a/movies/node.h b/movies/node.h index 7b0567f..71f4d6d 100644 --- a/movies/node.h +++ b/movies/node.h @@ -8,12 +8,17 @@ struct node { void* data; }; +// Appends Node to list void append_node(struct node*, struct node*); +// Creates node with value and appends +// Returns node that was created struct node* appendv_node(struct node*, void*); +// Counts the number of nodes in a list int count_nodes(struct node*); +// Iterates over every node in a list and runs the given function void iterate_nodes(struct node*, void *func(void*, void*), void*); #endif