diff --git a/Demonstration/book.h b/Demonstration/book.h index a43be45..73b0339 100644 --- a/Demonstration/book.h +++ b/Demonstration/book.h @@ -8,4 +8,4 @@ typedef struct { Book* book_create(const char* title, const char* author, int year); -void book_print(const void* data); \ No newline at end of file +void book_print(const void* data); diff --git a/Demonstration/main.c b/Demonstration/main.c index 52e2bb7..e360ee6 100644 --- a/Demonstration/main.c +++ b/Demonstration/main.c @@ -1,5 +1,6 @@ #include #include +#include #include "../Implementation/linked_list.h" #include "../../MenuLib/menu.h" @@ -73,6 +74,36 @@ void show_remove(Node** list) list_remove(list_get(*list, index)); } +void show_read(Node** list) +{ + char path[101], line[256], *title, *author, *year; + FILE* CSV; + + printf("Enter the path to the file of haram: "); + gets_s(path, 101); + + if (!(CSV = fopen(path, "r"))) + { + puts("Failed to read file!\n"); + return; + } + + while (fgets(line, 256, CSV)) + { + printf("Found line %s", line); + + title = strtok(line, ";"); + author = strtok(NULL, ";"); + year = strtok(NULL, ";"); + + printf("%s, %s, %s\n", title, author, year); + + list_push(list, book_create(title, author, atoi(year))); + + } + + fclose(CSV); +} void main(void) { @@ -85,6 +116,7 @@ void main(void) {"Print item", '4', (void*)&show_print, &list}, {"Look at item by index", '5', (void*)&show_get, &list}, {"Remove item by index", '6', (void*)&show_remove, &list}, + {"READ", 'r', (void*)&show_read, &list}, {"BLANK", ' ', NULL, NULL}, {"Quit", 'q', (void*)&exit, NULL} };