Add comments and clean up

This commit is contained in:
stitchy 2023-10-15 16:11:39 -07:00
parent 0fb4a5b117
commit be78c1dbfa
Signed by: stitchy
SSH key fingerprint: SHA256:yz2SoxdnY67tfY5Jzb0f2v8f5W3o/IF359kbcquWip8
5 changed files with 19 additions and 14 deletions

View file

@ -82,6 +82,7 @@ struct csv* parse_line(char* line) {
return mov; return mov;
} }
// Debugging; not used
void print_movies(struct node* head) { void print_movies(struct node* head) {
if(!head) { if(!head) {
@ -102,6 +103,7 @@ void print_movies(struct node* head) {
} }
} }
// Debugging; not used
void print_line(struct csv* printer) { void print_line(struct csv* printer) {
printf("%s, %i, ", printer->title, printer->year); 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 count_char(char* text, char cha) {
int length = strlen(text); int length = strlen(text);

View file

@ -6,6 +6,7 @@
#ifndef INPUT #ifndef INPUT
#define INPUT #define INPUT
// Error checking integer input
int integer_input(char*); int integer_input(char*);
#endif #endif

View file

@ -11,6 +11,7 @@ int main(int argc, char** argv) {
struct node* head = parse_csv(argv[1]); struct node* head = parse_csv(argv[1]);
// menu logic
enum OPTIONS menu_select = 0; enum OPTIONS menu_select = 0;
while(1) { while(1) {
@ -32,11 +33,7 @@ int main(int argc, char** argv) {
default: default:
printf("You naughty~ Pick a correct option next time.\n"); printf("You naughty~ Pick a correct option next time.\n");
} }
} }
print_movies(head);
return 0;
} }
int menu() { int menu() {
@ -71,6 +68,7 @@ void movie_year(struct node* head) {
*val = integer_input("Enter year to search movies from: "); *val = integer_input("Enter year to search movies from: ");
haschanged = 0; haschanged = 0;
// Prints each node if movie year the same as specified
iterate_nodes(head, f, val); iterate_nodes(head, f, val);
if(!haschanged) { if(!haschanged) {
@ -85,6 +83,7 @@ void lang_print(struct csv* data, void* val) {
for(int i = 0; i < data->numlang; i++) { for(int i = 0; i < data->numlang; i++) {
// Prints if movie is in given language
if(!strcmp(val, data->languages[i])) { if(!strcmp(val, data->languages[i])) {
printf("%d %s\n", data->year, data->title); printf("%d %s\n", data->year, data->title);
haschanged = 1; haschanged = 1;
@ -118,8 +117,6 @@ void check_year(int* data, int* year) {
if(*data == *year) if(*data == *year)
haschanged = 1; haschanged = 1;
//printf("%d, %d\n",*data, *year);
} }
void find_year(struct csv* data, void* 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; void* f = &check_year;
haschanged = 0; haschanged = 0;
// Finds every year that has a movie produced in our list
iterate_nodes(year, f, &data->year); iterate_nodes(year, f, &data->year);
if(!haschanged) { if(!haschanged)
appendv_node(year, &data->year); appendv_node(year, &data->year);
//printf("Change Val: %d\n", data->year);
}
haschanged = 0; haschanged = 0;
} }
void print_node(int* val, char* garbage) {
printf("%s\n", garbage);
}
void print_rating(struct csv* data, struct csv** val) { void print_rating(struct csv* data, struct csv** val) {
// Null case handled here
if(val[0] == NULL) { if(val[0] == NULL) {
if(data->year == haschanged) if(data->year == haschanged)
val[0] = data; val[0] = data;
return; return;
} }
// Sets pointer to movie struct of new highest rating
if(data->rating > val[0]->rating if(data->rating > val[0]->rating
&& data->year == haschanged) && data->year == haschanged)
val[0] = data; val[0] = data;
@ -166,6 +159,7 @@ void index_nodes(int* val, void* head) {
void* f = &print_rating; void* f = &print_rating;
// Find the node of highest rating for specified year
iterate_nodes(head, f, cur_val); iterate_nodes(head, f, cur_val);
printf("%d %2.1f %s\n", cur_val[0]->year, cur_val[0]->rating, cur_val[0]->title); printf("%d %2.1f %s\n", cur_val[0]->year, cur_val[0]->rating, cur_val[0]->title);

View file

@ -12,10 +12,12 @@
int menu(); int menu();
// Headers for the options called by menu
void movie_year(struct node*); void movie_year(struct node*);
void movie_rate(struct node*); void movie_rate(struct node*);
void movie_lang(struct node*); void movie_lang(struct node*);
// Menu Options
enum OPTIONS { enum OPTIONS {
YEAR = 1, YEAR = 1,
RATE = 2, RATE = 2,

View file

@ -8,12 +8,17 @@ struct node {
void* data; void* data;
}; };
// Appends Node to list
void append_node(struct node*, struct node*); 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*); struct node* appendv_node(struct node*, void*);
// Counts the number of nodes in a list
int count_nodes(struct node*); 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*); void iterate_nodes(struct node*, void *func(void*, void*), void*);
#endif #endif