1 /* 2 * datum.c 3 * 4 * Beispielprogramm Systemprogrammierung: Kapselung mit C 5 * 6 * Autor: H.Drachenfels 7 * Erstellt am: 21.12.2017 / 25.7.2018 (C11) 8 */
9
10 #include "datum.h"
11
12 #include <stddef.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <time.h>
16
17 struct class_datum
18 {
19 int tag;
20 int monat;
21 int jahr;
22 };
23
24 datum* datum_heute(void)
25 {
26 datum *this_p = (datum*) malloc(sizeof (datum));
27 if (!this_p) return NULL;
28
29 time_t t;
30 time(&t);
31 struct tm * heute = localtime(&t);
32 this_p->tag = heute->tm_mday;
33 this_p->monat = heute->tm_mon + 1;
34 this_p->jahr = heute->tm_year + 1900;
35
36 return this_p;
37 }
38
39 datum* datum_vom(int t, int m, int j)
40 {
41 if (t < 1 || t > 31 || m < 1 || m > 12)
42 {
43 return NULL;
44 }
45
46 datum *this_p = (datum*) malloc(sizeof (datum));
47 if (!this_p) return NULL;
48
49 this_p->tag = t;
50 this_p->monat = m;
51 this_p->jahr = j;
52
53 return this_p;
54 }
55
56 void datum_freigeben(datum *this_p)
57 {
58 free(this_p);
59 }
60
61 void datum_ausgeben(datum *this_p)
62 {
63 printf("%d-%02d-%02d\n", this_p->jahr, this_p->monat, this_p->tag);
64 }
65