diff --git a/movies/csv_parser.c b/movies/csv_parser.c index 48a0c77..8e0287d 100644 --- a/movies/csv_parser.c +++ b/movies/csv_parser.c @@ -1,11 +1,15 @@ #include "csv_parser.h" -struct node* parse_csv() { +struct node* parse_csv(char* name) { FILE * file; - file = fopen("movies_sample_1.csv", "r"); + file = fopen(name, "r"); + if(!file) { + printf("Your File was Stolen by the Gremlins\n"); + exit(66); - // Buffer File For chars + } +// Buffer File For chars char* buffer; size_t buff_size = 1000; size_t chars = -2; @@ -31,6 +35,8 @@ struct node* parse_csv() { free(buffer); fclose(file); + printf("Processed file %s and processed data for %d movies.\n\n", name, count_nodes(head)); + return head; } diff --git a/movies/csv_parser.h b/movies/csv_parser.h index db9bc47..1301c9a 100644 --- a/movies/csv_parser.h +++ b/movies/csv_parser.h @@ -17,7 +17,7 @@ struct csv { struct node* node; }; -struct node* parse_csv(); +struct node* parse_csv(char*); struct csv* parse_line(char*); diff --git a/movies/makefile b/movies/makefile index 6172042..ce5b84e 100644 --- a/movies/makefile +++ b/movies/makefile @@ -10,5 +10,8 @@ csv_parser.o: csv_parser.c csv_parser.h node.o: node.c node.h $(CC) -c node.c -o node.o +run: + ./movies movies_sample_1.csv + clean: rm -f *.o vgcore.* $(output) diff --git a/movies/movies.c b/movies/movies.c index ee706ef..31f85e4 100644 --- a/movies/movies.c +++ b/movies/movies.c @@ -1,12 +1,71 @@ #include "movies.h" -int main() { +int main(int argc, char** argv) { - struct node* head = parse_csv(); + if(argc < 2) { + printf("Please Specify Filename\n"); + return 64; + } - printf("Test\n"); + struct node* head = parse_csv(argv[1]); + enum OPTIONS menu_select = 0; + while(1) { + + menu_select = menu(); + + switch(menu_select) { + case YEAR: + movie_year(head); + break; + case RATE: + movie_rate(head); + break; + case LANGUAGE: + movie_lang(head); + break; + case EXIT: + printf("Goodbye~\n"); + return 0; + default: + printf("You naughty~ Pick a correct option next time.\n"); + } + + } print_movies(head); return 0; } + +int menu() { + + int option = 0; + + printf("1. Show movies released in the specified year\n"); + printf("2. Show highest rated movie for each year\n"); + printf("3. Show the title and year of release of all movies in a specific language\n"); + printf("4. Exit from the program\n\n"); + + while(option > 4 || option < 1) { + printf("Enter a choice from 1 to 4: "); + scanf("%i", &option); + } + + return option; +} + +void movie_year(struct node* head) { + printf("stub\n"); + +} + +void movie_rate(struct node* head) { + printf("stub\n"); + +} + +void movie_lang(struct node* head) { + + printf("stub\n"); + +} diff --git a/movies/movies.h b/movies/movies.h index a6d11ee..81607a1 100644 --- a/movies/movies.h +++ b/movies/movies.h @@ -9,5 +9,18 @@ #include "csv_parser.h" #include "node.h" +int menu(); + +void movie_year(struct node*); +void movie_rate(struct node*); +void movie_lang(struct node*); + +enum OPTIONS { + YEAR = 1, + RATE = 2, + LANGUAGE = 3, + EXIT = 4, +}; + #endif diff --git a/movies/node.c b/movies/node.c index e70c87d..b2cce29 100644 --- a/movies/node.c +++ b/movies/node.c @@ -28,3 +28,20 @@ struct node* appendv_node(struct node* head, void* data) { return node; } +int count_nodes(struct node* head) { + + int num = 1; + + if(!head) + return -1; + + struct node* temp = head; + while(temp->node) { + + temp = temp->node; + num++; + } + + return num; +} + diff --git a/movies/node.h b/movies/node.h index db2e628..8d1cd07 100644 --- a/movies/node.h +++ b/movies/node.h @@ -12,5 +12,6 @@ void append_node(struct node*, struct node*); struct node* appendv_node(struct node*, void*); +int count_nodes(struct node*); #endif