2020-01-23 13:08:54 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2020-01-23 15:01:17 +01:00
|
|
|
#include <string.h>
|
2020-01-23 13:08:54 +01:00
|
|
|
|
|
|
|
#include "../Implementation/linked_list.h"
|
2020-01-23 13:57:15 +01:00
|
|
|
#include "../../MenuLib/menu.h"
|
2020-01-23 14:11:20 +01:00
|
|
|
#include "book.h"
|
2020-01-23 13:08:54 +01:00
|
|
|
|
2020-01-23 13:57:15 +01:00
|
|
|
void show_push(Node** list)
|
|
|
|
{
|
|
|
|
char title[101], author[101];
|
|
|
|
int year;
|
|
|
|
|
|
|
|
printf("Enter title of Book: ");
|
|
|
|
scanf_s(" %[^\n]s", title, 101);
|
|
|
|
printf("Enter author of Book: ");
|
|
|
|
scanf_s(" %[^\n]s", author, 101);
|
|
|
|
printf("Enter year of Release: ");
|
|
|
|
scanf_s(" %d", &year);
|
|
|
|
|
|
|
|
list_push(list, book_create(title, author, year));
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_append(Node** list)
|
|
|
|
{
|
|
|
|
char title[101], author[101];
|
|
|
|
int year;
|
|
|
|
|
|
|
|
printf("Enter title of Book: ");
|
|
|
|
scanf_s(" %[^\n]s", title, 101);
|
|
|
|
printf("Enter author of Book: ");
|
|
|
|
scanf_s(" %[^\n]s", author, 101);
|
|
|
|
printf("Enter year of Release: ");
|
|
|
|
scanf_s(" %d", &year);
|
|
|
|
|
|
|
|
list_append(list, book_create(title, author, year));
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_insert(Node** list)
|
|
|
|
{
|
|
|
|
char title[101], author[101];
|
|
|
|
int year, index;
|
|
|
|
|
|
|
|
printf("Enter title of Book: ");
|
|
|
|
scanf_s(" %[^\n]s", title, 101);
|
|
|
|
printf("Enter author of Book: ");
|
|
|
|
scanf_s(" %[^\n]s", author, 101);
|
|
|
|
printf("Enter year of Release: ");
|
|
|
|
scanf_s(" %d", &year);
|
|
|
|
printf("Enter place after which book is inserted: ");
|
|
|
|
scanf_s(" %d", &index);
|
|
|
|
|
2020-01-23 14:11:20 +01:00
|
|
|
list_insert(list_get(*list, index), book_create(title, author, year));
|
2020-01-23 13:57:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_print(Node** list)
|
|
|
|
{
|
|
|
|
list_print(*list, &book_print);
|
|
|
|
}
|
|
|
|
|
2020-01-23 14:03:38 +01:00
|
|
|
void show_get(Node** list)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
printf("Enter place: ");
|
|
|
|
scanf_s(" %d", &index);
|
2020-01-23 14:11:20 +01:00
|
|
|
list_print(list_get(*list,index), &book_print);
|
2020-01-23 14:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_remove(Node** list)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
printf("Enter place: ");
|
|
|
|
scanf_s(" %d", &index);
|
2020-01-23 14:11:20 +01:00
|
|
|
list_remove(list_get(*list, index));
|
2020-01-23 14:03:38 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 15:01:17 +01:00
|
|
|
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);
|
|
|
|
}
|
2020-01-23 14:03:38 +01:00
|
|
|
|
2020-01-23 13:08:54 +01:00
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
Node* list = NULL;
|
2020-01-23 13:57:15 +01:00
|
|
|
|
|
|
|
struct MenuItem items[] = {
|
|
|
|
{"Push item", '1', (void*)&show_push, &list},
|
|
|
|
{"Append item", '2', (void*)&show_append, &list},
|
|
|
|
{"Insert item", '3', (void*)&show_insert, &list},
|
|
|
|
{"Print item", '4', (void*)&show_print, &list},
|
2020-01-23 14:03:38 +01:00
|
|
|
{"Look at item by index", '5', (void*)&show_get, &list},
|
|
|
|
{"Remove item by index", '6', (void*)&show_remove, &list},
|
2020-01-23 15:01:17 +01:00
|
|
|
{"READ", 'r', (void*)&show_read, &list},
|
2020-01-23 14:11:20 +01:00
|
|
|
{"BLANK", ' ', NULL, NULL},
|
2020-01-23 13:57:15 +01:00
|
|
|
{"Quit", 'q', (void*)&exit, NULL}
|
|
|
|
};
|
|
|
|
struct MenuPage pages[] = {
|
|
|
|
{items, sizeof(items) / sizeof(struct MenuItem), "Linked List Demo", true, true, &SOLID}
|
|
|
|
};
|
|
|
|
show_menu(pages, sizeof(pages) / sizeof(struct MenuPage), true);
|
2020-01-23 13:08:54 +01:00
|
|
|
}
|