From 9136bc774047706a00f0844acd3479fb18c45c99 Mon Sep 17 00:00:00 2001 From: stitchy Date: Wed, 25 Oct 2023 13:09:11 -0700 Subject: [PATCH] Finished main program; waiting on UI --- directories/movies_by_year.c | 88 ++++++++++++++++++++++++++++++++++++ directories/movies_by_year.h | 30 ++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 directories/movies_by_year.c create mode 100644 directories/movies_by_year.h diff --git a/directories/movies_by_year.c b/directories/movies_by_year.c new file mode 100644 index 0000000..98897ed --- /dev/null +++ b/directories/movies_by_year.c @@ -0,0 +1,88 @@ +#include "movies_by_year.h" + +int haschanged = 0; + +int main() { + + // seed random seed + srand(time(NULL)); + + struct node* head = parse_csv("movies_sample_1.csv"); + + // Generate the String for movies + char* dir = malloc(sizeof(char)*100); + sprintf(dir, "temp.movies.%d", rand() % 100000); + + return 0; +} + +void write_file(struct csv* node, FILE* mov_file) { + + if(haschanged == node->year) + fprintf(mov_file, "%s\n", node->title); + +} + +void index_nodes(int* val, void* head) { + + haschanged = *val; + + char* textfile = malloc(sizeof(char)*30); + + sprintf(textfile, "%d.txt", *val); + + FILE* movie_file = fopen(textfile, "w"); + + void* f = &write_file; + + // Find the node of highest rating for specified year + iterate_nodes(head, f, movie_file); + + fclose(movie_file); + haschanged = 0; + +} + +void print_csv(struct node* head, char* dir) { + + int result = mkdir(dir, 0750); + printf("%d\n", result); + + chdir(dir); + + struct csv* temp = head->data; + struct node* year = appendv_node(NULL, &temp->year); + void* f = &find_year; + + // Do the node list + iterate_nodes(head, f, year); + + void* tempish = &index_nodes; + + // Iterate through every year year + iterate_nodes(year, tempish, head); + +} + +void check_year(int* data, int* year) { + + if(*data == *year) + haschanged = 1; + +} + +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) + appendv_node(year, &data->year); + + haschanged = 0; + +} + diff --git a/directories/movies_by_year.h b/directories/movies_by_year.h new file mode 100644 index 0000000..b0c8f2b --- /dev/null +++ b/directories/movies_by_year.h @@ -0,0 +1,30 @@ + + +#ifndef MOVIES_YEAR +#define MOVIES_YEAR + +#include "stdio.h" +#include "stdlib.h" +#include "time.h" +#include +#include + +#include "csv_parser.h" +#include "node.h" +#include "input.h" + +int menu(); + +void print_csv(struct node*, char*); + +// Menu Options +enum OPTIONS { + YEAR = 1, + RATE = 2, + LANGUAGE = 3, + EXIT = 4, +}; + +void find_year(struct csv*, void*); + +#endif