#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; }