-
Notifications
You must be signed in to change notification settings - Fork 0
/
day.h
66 lines (60 loc) · 1.57 KB
/
day.h
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
/**
* Defines the Day of the Week (DotW) enum.
* Defines the Day struct and all the function headers related to it.
* @author Marcelo F. Cabral ([email protected])
*/
#include"list.c"
#ifndef DAY_H
#define DAY_H
/**
* enum DotW: facilitates the comprehension of code when referring to numeric values associated to days of the week.
* 0 is Sunday, 1 is Monday, ... , 6 is Saturday.
*/
enum DotW{Sun, Mon, Tue, Wed, Thu, Fri, Sat};
/**
* Translates a valid enum DotW into a string.
* @param d an integer, ideally inside the interval [0, 6],
* @return the corresponding day of the week's name string.
*/
char* getDayName(enum DotW d){
char *name = (char*) malloc(sizeof(char)*4);
switch(d){
case Sun:
strcpy(name, "Sun");
break;
case Mon:
strcpy(name, "Mon");
break;
case Tue:
strcpy(name, "Tue");
break;
case Wed:
strcpy(name, "Wed");
break;
case Thu:
strcpy(name, "Thu");
break;
case Fri:
strcpy(name, "Fri");
break;
case Sat:
strcpy(name, "Sat");
break;
default:
printf("Invalid day!\n");
free(name);
break;
}
return name;
}
/**
* struct Day: holds a DotW enum that represents which day of the week the current struct is associated to,
* aswell as a pointer to a List struct.
*/
typedef struct Day{
enum DotW d;
List *l;
}Day;
Day createDay(enum DotW _d);
void printDay(Day Day);
#endif