-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank_example.c
More file actions
50 lines (44 loc) · 1.41 KB
/
bank_example.c
File metadata and controls
50 lines (44 loc) · 1.41 KB
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
/**
* \file bank_example.c
* \brief Quick example using the library in C
*
* To run:
* >>> make
* >>> LD_LIBRARY_PATH=$PWD/banking:$LD_LIBRARY_PATH ./bank_example.exe
*/
#include <stdio.h>
#include "banking/banking.h"
/** Print the result of a transaction. */
void print_result(const struct Receipt receipt) {
printf(
"Receipt, Status: %d, Cash returned: %d, Current balance: %d\n",
receipt.status,
receipt.cash_returned,
receipt.balance
);
};
/**
* The example code.
*
* Creates a bank and runs some commands, printing out results.
*/
int main() {
printf("Creating bank\n");
struct BankHandler* handler = createBank();
printf("Creating account\n");
createAccount(handler, "bill gates", "msft", 100);
printf("Checking balance, wrong account\n");
print_result(checkBalance(handler, "jeff bezos", "amzn"));
printf("Checking balance, wrong password\n");
print_result(checkBalance(handler, "bill gates", "amzn"));
printf("Checking balance\n");
print_result(checkBalance(handler, "bill gates", "msft"));
printf("Deposit money\n");
print_result(deposit(handler, "bill gates", "msft", 10));
printf("Withdraw money\n");
print_result(withdraw(handler, "bill gates", "msft", 15));
printf("Trying to withdraw too much\n");
print_result(withdraw(handler, "bill gates", "msft", 1000));
destroyBank(handler);
return 0;
}