-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateAccount.c
71 lines (70 loc) · 1.88 KB
/
createAccount.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
63
64
65
66
67
68
69
70
71
#include "myheader.h"
#include <stdio.h>
#include<string.h>
void createAccount(){
Bank bank;
FILE *fb = fopen("bank.txt", "r");
FILE *fp = fopen("data.txt", "a");
if (fb != NULL && fgetc(fb) != EOF) {
rewind(fb);
fscanf(fb, "%d %d %s", &bank.total_users, &bank.total_balance, bank.password);
} else {
showErrorMessage();
return;
}
if (fp == NULL) {
showErrorMessage();
return;
}
User new_user;
fflush(stdin);
setColor(BLUE);
puts("Enter Details");
resetColor();
printf("Name: ");
gets(new_user.name);
printf("Age: ");
scanf("%d", &new_user.age);
setColor(BLUE);
printf("Account Type:\n");
setColor(GREEN);
puts("1. Savings\n2. Current");
resetColor();
printf("Enter opt no: ");
int x;
scanf("%d", &x);
if (x == 1) strcpy(new_user.ac_type, "savings");
else if (x == 2) strcpy(new_user.ac_type, "current");
else {
clearScreen();
showErrorMessage();
return;
}
printf("Deposit amount: ");
scanf("%d", &new_user.balance);
new_user.ac_no = bank.total_users++ + 1111;
bank.total_balance += new_user.balance;
fprintf(fp, "%d:\n%s\n%d %s %d\n", new_user.ac_no, new_user.name, new_user.age, new_user.ac_type, new_user.balance);
printf("Account created for : ");
setColor(GREEN);
printf("%s\n", new_user.name);
resetColor();
printf("Balance: ");
setColor(GREEN);
printf("%d\n", new_user.balance);
resetColor();
printf("%s's account number is: ", new_user.name);
setColor(GREEN);
printf("%d\n", new_user.ac_no);
resetColor();
updateBankInfo(bank.total_users, bank.total_balance, bank.password);
fclose(fp);
fclose(fb);
setColor(GREEN);
printf("\n\nPress enter to continue...");
resetColor();
fflush(stdin);
getchar();
clearScreen();
return;
}