From 1a79de28823278096172b2d9ed6b7aeb37ab0169 Mon Sep 17 00:00:00 2001 From: Rory Healy Date: Sat, 16 May 2020 22:36:50 +1000 Subject: [PATCH] Basic formatting and struct creation --- src/main.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 1a263e5..afcfb10 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,102 @@ #include +#include + +#define STAGE_FORMATTING_STRING "=========================" +#define STAGE_ONE 1 +#define STAGE_TWO 2 +#define STAGE_THREE 3 +#define STAGE_FOUR 4 + +#define MAX_NUM_CARDS 100 +#define CREDIT_CARD_ID_LEN 8 +#define TRANSACTION_ID_LEN 12 +#define TRANSACTION_TIME_LEN 19 +#define END_CREDIT_CARDS "%%%%%%%%%%" + +typedef struct { + char card_id[CREDIT_CARD_ID_LEN]; + int daily_lim; + int trans_lim; +} credit_card_t; + +typedef struct { + char trans_id[TRANSACTION_ID_LEN]; + char card_id[CREDIT_CARD_ID_LEN]; + char trans_time[TRANSACTION_TIME_LEN]; + int trans_amount; +} transaction_t; + +void print_stage(int stage_num); +void stage_one(); +void stage_two(); +void stage_three(); +void stage_four(); + +int main(int argc, char *argv[]) { + /* holds all the credit cards */ + credit_card_t all_cards[MAX_NUM_CARDS]; + + /* holds all the transactions */ + transaction_t all_transactions[MAX_NUM_CARDS]; + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * Dynamic memory allocation required as + * size of all_transactions isn't known + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + + /* stage 1: reading one credit card record */ + stage_one(); + + /* stage 2: reading all credit card records */ + stage_two(); + + /* stage 3: reading the transactions */ + stage_three(); + + /* stage 4: checking for fraudulent transactions */ + stage_four(); -int main() { return 0; +} + +/* print the stage header */ +void print_stage(int stage_num) { + printf(STAGE_FORMATTING_STRING); + printf("Stage %d", stage_num); + printf(STAGE_FORMATTING_STRING); + printf("\n"); +} + +/* stage 1: reading one credit card record */ +void stage_one() { + print_stage(STAGE_ONE); + + + + printf("\n"); +} + +/* stage 2: reading all credit card records */ +void stage_two() { + print_stage(STAGE_TWO); + + + + printf("\n"); +} + +/* stage 3: reading the transactions */ +void stage_three() { + print_stage(STAGE_THREE); + + + printf("\n"); +} + +/* stage 4: checking for fraudulent transactions */ +void stage_four() { + print_stage(STAGE_FOUR); + + + printf("\n"); } \ No newline at end of file