-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.c
More file actions
63 lines (53 loc) · 1.43 KB
/
driver.c
File metadata and controls
63 lines (53 loc) · 1.43 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
#include "driver.h"
#include "team.h"
#include "season.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
struct driver {
int id;
char* name;
Team team;
int points;
Season season;
};
static bool UpdateAllocationMemoryStatus(DriverStatus* status, void* p){
if (p == NULL) {
*status=DRIVER_MEMORY_ERROR;
return false;
}
*status=DRIVER_STATUS_OK;
return true;
}
Driver DriverCreate(DriverStatus* status, char* driver_name, int driverId){
Driver driver = malloc(sizeof(*driver));
if (!UpdateAllocationMemoryStatus(status, driver)) return NULL;
char* driver_name_copy = malloc(sizeof(*driver_name_copy)*(strlen(driver_name)+1));
if (!UpdateAllocationMemoryStatus(status, driver->name)) return NULL;
strcpy(driver_name_copy, driver_name);
driver->id = driverId;
driver->name = driver_name_copy;
return driver;
}
void DriverDestroy(Driver driver){
free(driver->name);
free(driver);
}
const char* DriverGetName(Driver driver){
if (driver == NULL) return NULL;
return driver->name;
}
Team DriverGetTeam(Driver driver){
if (driver == NULL) return NULL;
return driver->team;
}
int DriverGetId(Driver driver){
if (driver == NULL) return NULL;
return driver->id;
}
void DriverSetTeam(Driver driver, Team team){
driver->team = team;
}
void DriverSetSeason(Driver driver, Season season){
}