diff --git a/directories/csv_parser.c b/directories/csv_parser.c index a08b9fe..ed84b9b 100644 --- a/directories/csv_parser.c +++ b/directories/csv_parser.c @@ -6,7 +6,8 @@ struct node* parse_csv(char* name) { file = fopen(name, "r"); if(!file) { perror("Error"); - exit(66); + printf("\n"); + return NULL; } // Buffer File For chars @@ -35,7 +36,7 @@ struct node* parse_csv(char* name) { free(buffer); fclose(file); - printf("Processed file %s and processed data for %d movies.\n\n", name, count_nodes(head)); + printf("Processed file %s and processed data for %d movies.\n", name, count_nodes(head)); return head; diff --git a/directories/movies_by_year.c b/directories/movies_by_year.c index 1ff91a7..d38f2e6 100644 --- a/directories/movies_by_year.c +++ b/directories/movies_by_year.c @@ -92,11 +92,14 @@ void choose_movie(char* dir_str) { //printf("\nDirectory: %s\n", dir_str); struct node* head = parse_csv(dir_str); + if(!head) + return; + // Generate the String for movies char* dir = malloc(sizeof(char)*100); sprintf(dir, "temp.movies.%d", rand() % 100000); - printf("Created directory with the name %s\n", dir); + printf("Created directory with the name %s\n\n", dir); print_csv(head, dir); free(dir_str); @@ -132,6 +135,9 @@ void index_nodes(int* val, void* head) { void print_csv(struct node* head, char* dir) { + if(!head) + return; + int result = mkdir(dir, 0750); chdir(dir); diff --git a/directories/readme.md b/directories/readme.md index 3a3c009..185eb40 100644 --- a/directories/readme.md +++ b/directories/readme.md @@ -34,5 +34,5 @@ make run To specify a CSV file, you can type: ``` -./movies_by_year $(CSV_File_to_read.csv) +./movies_by_year ```