-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.c
89 lines (73 loc) · 1.81 KB
/
event.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This is an Academic Project, and was published after finishing the lecture.
// @author Joao Elvas @ FCT/UNL
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "event.h"
/**
* Print a list of events
* eventList - the list of events
*/
void print_event_list(EventList *eventList) {
printf("Listing %d events.\n", eventList->nEvents);
int i = 0;
for ( ; i < eventList->nEvents; i++)
print_event("", &eventList->events[i]);
}
/**
* Print an event
* text - prefix text
* event - the event to print
*/
void print_event(char* text, Event* event) {
float hour = ((float) hour(event))/100;
printf("%s\n Id: %u\n Date: %u/%u/%u Hour: %.2f\n Duration: %u minutes\n Description: %s\n Created by: %s\n",
text, id(event), day(event), month(event), year(event), hour, duration(event),
description(event), user(event));
}
/**
* Create a list of events
* nEvents - the length of the list
*/
EventList* new_event_list(int nEvents) {
EventList* eventList = (EventList* ) malloc(sizeof(EventList));
eventList->nEvents = nEvents;
eventList->events = malloc(sizeof(Event) * nEvents);
return eventList;
}
/**
* Destroy a list of events
* eventList - the list of events
*/
void destroy_event_list(EventList *eventList) {
free(eventList->events);
free(eventList);
}
// Validation functions
int validate_user(char* user) {
return (strlen(user) <= MAX_USER);
}
int validate_year(short year) {
// NOT IMPLEMENTED
return 1;
}
int validate_month(short month) {
// NOT IMPLEMENTED
return 1;
}
int validate_day(short day) {
// NOT IMPLEMENTED
return 1;
}
int validate_hour(short hour) {
// NOT IMPLEMENTED
return 1;
}
int validate_duration(short duration) {
// NOT IMPLEMENTED
return 1;
}
int validate_description(char* description) {
// NOT IMPLEMENTED
return 1;
}