Basic formatting and struct creation
This commit is contained in:
parent
789e415f7b
commit
1a79de2882
1 changed files with 98 additions and 1 deletions
99
src/main.c
99
src/main.c
|
@ -1,5 +1,102 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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");
|
||||
}
|
Loading…
Reference in a new issue