forked from embedded2015/phonebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonebook_orig.c
47 lines (41 loc) · 937 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "phonebook_orig.h"
/* original version */
entry *findName(char lastname[], entry *pHead)
{
while (pHead != NULL) {
if (strcasecmp(lastname, pHead->lastName) == 0)
return pHead;
pHead = pHead->pNext;
}
return 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;
addnull(lastName);
strcpy(e->lastName, lastName);
e->pNext = NULL;
return e;
}
entry *initialize(entry *pHead)
{
pHead = (entry*) malloc(sizeof(entry));
printf("size of entry : %lu bytes\n", sizeof(entry));
pHead->pNext = NULL;
return pHead;
}
//replace \n with \0
void addnull(char *line)
{
int i = 0;
while (line[i] != '\0')
i++;
line[i - 1] = '\0';
return;
}