-
Notifications
You must be signed in to change notification settings - Fork 4
/
building.c
55 lines (47 loc) · 1.07 KB
/
building.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
#include "building.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
const char *buildingtypenames[] = {
"longboat",
"clipper",
"galleon",
};
building *create_building(int no) {
building *b = (building *)calloc(1, sizeof(building));
assert(no);
if (b) {
b->no = no;
}
return b;
}
void free_building(building *b) {
free(b->name_);
free(b->display_);
free(b);
}
const char * building_getname(const struct building *self)
{
return self->name_;
}
void building_setname(struct building *self, const char *name)
{
assert(name);
self->name_ = (char *)realloc(self->name_, strlen(name)+1);
strcpy(self->name_, name);
}
const char * building_getdisplay(const struct building *self)
{
return self->display_;
}
void building_setdisplay(struct building *self, const char *display)
{
if (display) {
self->display_ = (char *)realloc(self->display_, strlen(display)+1);
strcpy(self->display_, display);
} else {
free(self->display_);
self->display_ = 0;
}
}