-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistcard.c
62 lines (51 loc) · 1.77 KB
/
listcard.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <malloc.h>
#include <time.h>
#include "listcard.h"
#include "addcard.h"
#include "safeinput.h"
#include "card.h"
#include "cardlist.h"
#include "adminmenu.h"
#include "fileio.h"
void insertStartCards(CARDLIST *cardList) {
// Initializing 2 default cards, presented during the briefing of the project.
time_t current_time;
struct tm* time_info;
time(¤t_time);
time_info = localtime(¤t_time);
CARD card1;
card1.cardId = 1212;
card1.accessGranted = true;
snprintf(card1.timeStamp, sizeof(card1.timeStamp), "%d-%02d-%02d",
time_info->tm_year + 1900, time_info->tm_mon + 1, time_info->tm_mday);
CARD card2;
card2.cardId = 1213;
card2.accessGranted = false;
struct tm* time_info2 = localtime(¤t_time);
snprintf(card2.timeStamp, sizeof(card2.timeStamp), "%d-%02d-%02d",
time_info2->tm_year + 1900, time_info2->tm_mon + 1, time_info2->tm_mday);
cardList->list = malloc(2 * sizeof(CARD));
cardList->list[0] = card1;
cardList->list[1] = card2;
cardList->count = 2;
}
// The following short functions: printCard and listCard, are used to present cards to the user in the console.
void printCard (const CARD *card){
if (card == NULL) {
printf("ERROR: Invalid card pointer.\n");
return;
}
printf("Card ID: %d\nAccess Granted: %s\nTimestamp: %s\n",
card->cardId, card->accessGranted ? "Yes" : "No", card->timeStamp);
}
void listCard(const CARDLIST *cardList) {
for (int i = 0; i < cardList->count;i++){
printf("\t\n--- CARD NR %d --- \n", i+1);
printCard(&(cardList->list[i]));
}
printf("\nTotal amount of cards in the system: %d\n", cardList->count);
}