-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFILE.C
71 lines (59 loc) · 1.53 KB
/
FILE.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 "ATM.H"
h *list1 = NULL, *temp;
int insert(h * newNode){
if(list1 == NULL){
list1 = newNode;
}
else{
temp = list1;
while(temp -> next != NULL){
temp = temp -> next;
}
temp -> next = newNode;
}
}
h* scanffile(REC user)
{
FILE *fp;
int dd, yy,mm, hr,mn,sec;
double credit,debit;
h *newnode,*reList;
char *filename = strcat(user.accNumber,".TXT");
if((fp = fopen(filename, "r")) != NULL){
while((fscanf(fp,"%lf %lf %d %d %d %d %d %d\n",&credit,&debit,&dd,&mm,&yy,&hr,&mn,&sec)) != EOF){
newnode = (struct node1*)malloc(sizeof(struct node1));
if(newnode != NULL){
newnode -> credit = credit;
newnode -> debit = debit;
newnode -> dd = dd;
newnode -> yy = yy;
newnode -> mm = mm;
newnode -> hr = hr;
newnode -> mn = mn;
newnode -> sec = sec;
newnode -> next = NULL;
insert(newnode);
}
else{
printf("\nUnable to allocate!");
}
}
}
fclose(fp);
reList = list1;
list1 = NULL;
return reList;
}
void save(REC user,double debit, struct date dt, struct time tm){
FILE *newFile,*oldFile;
char *filename = strcat(user.accNumber,".TXT");
if((oldFile = fopen(filename,"a")) != NULL){
fprintf(oldFile,"%.2lf %.2lf %d %d %d %d %d %d\n",user.money, debit,dt.da_day,dt.da_mon, dt.da_year,tm.ti_hour, tm.ti_min, tm.ti_sec);
}
else{
newFile = fopen(filename,"w");
fprintf(newFile,"%.2lf %.2lf %d %d %d %d %d %d\n",user.money, debit,dt.da_day,dt.da_mon, dt.da_year,tm.ti_hour, tm.ti_min, tm.ti_sec);
}
fclose(newFile);
fclose(oldFile);
}