kske
/
linked-list
Archived
1
Fork 0

Implemented Writing Files

Implemented Writing Files with user-inputed path. Or something like this. idk
This commit is contained in:
ertz4 2020-01-23 15:16:56 +01:00
parent 467e308cb6
commit b22a0977aa
1 changed files with 31 additions and 4 deletions

View File

@ -105,6 +105,32 @@ void show_read(Node** list)
fclose(CSV);
}
void show_write(Node** list)
{
char path[101], line[256];
FILE* CSV;
Node* node = *list;
Book* book;
printf("Enter the path to the file_s: ");
gets_s(path, 101);
if (!(CSV = fopen(path, "w")))
{
puts("Failed to read file!\n");
return;
}
while (node)
{
book = (Book*)node->data;
fprintf(CSV, "%s;%s;%d\n", book->title, book->author, book->year);
node = node->next;
}
fclose(CSV);
}
void main(void)
{
Node* list = NULL;
@ -117,6 +143,7 @@ void main(void)
{"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},
{"RIDE", 'w', (void*)&show_write, &list},
{"BLANK", ' ', NULL, NULL},
{"Quit", 'q', (void*)&exit, NULL}
};