Implemented Writing Files
Implemented Writing Files with user-inputed path. Or something like this. idk
This commit is contained in:
parent
467e308cb6
commit
b22a0977aa
@ -105,6 +105,32 @@ void show_read(Node** list)
|
|||||||
fclose(CSV);
|
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)
|
void main(void)
|
||||||
{
|
{
|
||||||
Node* list = NULL;
|
Node* list = NULL;
|
||||||
@ -117,6 +143,7 @@ void main(void)
|
|||||||
{"Look at item by index", '5', (void*)&show_get, &list},
|
{"Look at item by index", '5', (void*)&show_get, &list},
|
||||||
{"Remove item by index", '6', (void*)&show_remove, &list},
|
{"Remove item by index", '6', (void*)&show_remove, &list},
|
||||||
{"READ", 'r', (void*)&show_read, &list},
|
{"READ", 'r', (void*)&show_read, &list},
|
||||||
|
{"RIDE", 'w', (void*)&show_write, &list},
|
||||||
{"BLANK", ' ', NULL, NULL},
|
{"BLANK", ' ', NULL, NULL},
|
||||||
{"Quit", 'q', (void*)&exit, NULL}
|
{"Quit", 'q', (void*)&exit, NULL}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user