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;
}
// 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);

View file

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

View file

@ -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);

View file

@ -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,

View file

@ -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