-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmap_stuff.c
More file actions
73 lines (58 loc) · 1.76 KB
/
map_stuff.c
File metadata and controls
73 lines (58 loc) · 1.76 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
65
66
67
68
69
70
71
72
#include <stdio.h>
#include "map_lib.h"
void display_both(struct map_t *m,char *key);
int main(int argc,char **argv) {
struct map_t *test;
test=map_create();
if(test==NULL) {
fprintf(stderr,"Cannot create map_t struct\n");
return 1;
}
map_set(test,"One","Won");
if(test->error_code) {
fprintf(stderr,"Error %d in line %d of map_lib.c\n",test->error_code, test->error_line);
return 1;
}
map_set(test,"Two","Too");
if(test->error_code) {
fprintf(stderr,"Error %d in line %d of map_lib.c\n",test->error_code, test->error_line);
return 1;
}
map_set(test,"Four","Fore");
if(test->error_code) {
fprintf(stderr,"Error %d in line %d of map_lib.c\n",test->error_code, test->error_line);
return 1;
}
// display them out of order
display_both(test,"Two");
display_both(test,"Four");
display_both(test,"One");
printf("\n");
// reset an existing entry
map_set(test,"Two","To");
if(test->error_code) {
fprintf(stderr,"Error %d in line %d of map_lib.c\n",test->error_code, test->error_line);
return 1;
}
display_both(test,"Two");
display_both(test,"Four");
display_both(test,"One");
printf("\n");
display_both(test,"Eight");
map_set(test,"Eight","Ate");
printf("\n");
display_both(test,"Eight");
printf("---\n");
// test some null checking
map_set(test,NULL,"nothing");
if(test->error_code) {
fprintf(stderr,"Error %d in line %d of map_lib.c\n",test->error_code, test->error_line);
}
map_set(test,"nothing",NULL);
if(test->error_code) {
fprintf(stderr,"Error %d in line %d of map_lib.c\n",test->error_code, test->error_line);
}
}
void display_both(struct map_t *m,char *first) {
printf("%s %s\n",first,map_get(m,first));
}