Added CSV deserialization for demo project
This commit is contained in:
parent
6c4fb1ef14
commit
467e308cb6
@ -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}
|
||||
};
|
||||
|
Reference in New Issue
Block a user