Finished main program; waiting on UI
This commit is contained in:
parent
5daf5d6e02
commit
9136bc7740
2 changed files with 118 additions and 0 deletions
88
directories/movies_by_year.c
Normal file
88
directories/movies_by_year.c
Normal file
|
@ -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;
|
||||
|
||||
}
|
||||
|
30
directories/movies_by_year.h
Normal file
30
directories/movies_by_year.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
|
||||
#ifndef MOVIES_YEAR
|
||||
#define MOVIES_YEAR
|
||||
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "time.h"
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#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
|
Loading…
Reference in a new issue