forked from embedded2015/phonebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonebook_orig.c
executable file
·56 lines (48 loc) · 994 Bytes
/
phonebook_orig.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "phonebook_orig.h"
void initialize()
{
pHead = (entry *) malloc(sizeof(entry));
e = pHead;
e->pNext = NULL;
}
entry *append(char lastName[], entry *e)
{
/* allocate memory for the new entry and put lastName */
e->pNext = (entry *) malloc(sizeof(entry));
e = e->pNext;
strcpy(e->lastName, lastName);
e->pNext = NULL;
return e;
}
void new_node(char lastName[], entry *node)
{
e = append(lastName, node);
}
void move_node()
{
e = pHead;
}
entry *findName(char lastname[], entry *pHead)
{
while (pHead != NULL) {
if (strcasecmp(lastname, pHead->lastName) == 0)
return pHead;
pHead = pHead->pNext;
}
return NULL;
}
void release()
{
free(pHead);
}
struct PHONE_BOOK PHONE_BOOK = {
.initialize = initialize,
.move_node = move_node,
.new_node = new_node,
.findName = findName,
.release = release
};