-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
64 lines (51 loc) · 1.2 KB
/
list.c
File metadata and controls
64 lines (51 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "list.h"
#include <stdlib.h>
#include <stdio.h>
struct List *addNode(struct List *list, void *head, int dataSize)
{
// New pointer to point at the new begining
struct List *newNode = (struct List *)malloc(sizeof(struct List));
// New
newNode->head=head;
// Insert new node before any other element:
newNode->next=list;
return newNode;
}
struct List *removenode(struct List *list)
{
return NULL;
}
void savelist(struct List *list, int dataSize)
{
FILE * pFile;
pFile = fopen ("myfile.bin", "wb");
while (list != NULL)
{
fwrite(list->head, dataSize , 1, pFile);
list = list->next;
}
fclose(pFile);
}
struct List *loadList(int dataSize)
{
struct List *list;
struct List *temp_list;
list = NULL;
FILE * pFile;
pFile = fopen("myfile.bin", "rb");
// obtain file size:
// int lSize;
// fseek (pFile , 0 , SEEK_END);
// lSize = ftell (pFile);
// rewind (pFile);
temp_list = (struct List *)malloc(sizeof(struct List));
void *head = malloc(dataSize);
while(fread(head, dataSize, 1 , pFile) == 1){
temp_list->head = head;
temp_list->next = list;
list=temp_list;
temp_list = (struct List *)malloc(sizeof(struct List));
head = malloc(dataSize);
}
return list;
}