kske
/
linked-list
Archived
1
Fork 0

Added CSV deserialization for demo project

This commit is contained in:
ertz4 2020-01-23 15:01:17 +01:00
parent 6c4fb1ef14
commit 467e308cb6
2 changed files with 33 additions and 1 deletions

View File

@ -8,4 +8,4 @@ typedef struct {
Book* book_create(const char* title, const char* author, int year);
void book_print(const void* data);
void book_print(const void* data);

View File

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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}
};