-
Notifications
You must be signed in to change notification settings - Fork 1
/
savelist.c
78 lines (64 loc) · 1.3 KB
/
savelist.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Lista para armazenamento de erros
#include <string.h>
struct test_struct
{
unsigned int val;
char error[70];
struct test_struct *next;
};
struct test_struct *head = NULL;
struct test_struct *curr = NULL;
struct test_struct* create_list(char *erro)
{
struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
if(NULL == ptr)
{
return NULL;
}
ptr->val = 0;
strcpy(ptr->error, erro);
ptr->next = NULL;
head = curr = ptr;
return ptr;
}
struct test_struct* add_to_list(int val, char *erro)
{
struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
if(NULL == ptr)
{
return NULL;
}
ptr->val = val;
strcpy(ptr->error, erro);
ptr->next = NULL;
curr->next = ptr;
curr = ptr;
return ptr;
}
unsigned char *search_in_list(char *erro)
{
struct test_struct *ptr = head;
struct test_struct *tmp = NULL;
while(ptr != NULL)
{
if(strstr(ptr->error, erro) != NULL)
{
break;
}
else
{
tmp = ptr;
ptr = ptr->next;
}
}
return ptr->error;
}
void print_list(void)
{
struct test_struct *ptr = head;
while(ptr != NULL)
{
ptr = ptr->next;
}
return;
}