-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.c
More file actions
158 lines (145 loc) · 4.02 KB
/
data.c
File metadata and controls
158 lines (145 loc) · 4.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*Populating records*/
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<stdio.h>
typedef struct normalUser{
int userID;
char username[30];
char password[10];
int account_no;
float balance;
char status[20];
}normalUser;
typedef struct jointUser{
int userID;
char username1[30];
char username2[30];
char password[10];
int account_no;
float balance;
char status[20];
}jointUser;
typedef struct admin{
int userID;
char username[30];
char password[10];
}admin;
int newUserTyp1();
int newUserTyp2();
int newUserTyp3();
int newUserTyp1(){
int fd=open("nu",O_RDONLY,0744);
normalUser record;
lseek(fd,-sizeof(normalUser),SEEK_END);
read(fd,&record,sizeof(normalUser));
close(fd);
return record.userID+1;
}
int newUserTyp2(){
int fd=open("ju",O_RDONLY,0744);
jointUser record;
lseek(fd,-sizeof(jointUser),SEEK_END);
read(fd,&record,sizeof(jointUser));
close(fd);
return record.userID+1;
}
int newUserTyp3(){
int fd=open("adm",O_RDONLY,0744);
admin record;
lseek(fd,-sizeof(admin),SEEK_END);
read(fd,&record,sizeof(admin));
close(fd);
return record.userID+1;
}
int main(){
int fd=open("adm",O_RDWR | O_CREAT,0744);
int choice=0;
admin newAdm;
printf("Enter the name of the admin: ");
scanf(" %s",newAdm.username);
printf("Enter the password(max 10 characters): ");
scanf(" %s",newAdm.password);
newAdm.userID=1000;
printf("Your userID is : %d\n",newAdm.userID);
write(fd,&newAdm,sizeof(newAdm));
printf("Do you want to continue(0-No/1-Yes) ?");
scanf("%d",&choice);
while(choice){
printf("Enter the name of the admin: ");
scanf(" %[^\n]",newAdm.username);
printf("Enter the password(max 10 characters): ");
scanf(" %[^\n]",newAdm.password);
newAdm.userID=newUserTyp3();
printf("Your userID is : %d\n",newAdm.userID);
write(fd,&newAdm,sizeof(admin));
printf("Do you want to continue(0-No/1-Yes) ?");
scanf("%d",&choice);
}
close(fd);
fd=open("nu",O_RDWR | O_CREAT,0744);
choice=1;
normalUser newNu;
printf("Enter the name of the normal user: ");
scanf(" %[^\n]",newNu.username);
printf("Enter the password(max 10 characters): ");
scanf(" %[^\n]",newNu.password);
newNu.userID=1000;
newNu.balance=1000;
newNu.account_no=(newNu.userID-1000)+100000;
printf("Your userID is : %d\n",newNu.userID);
strcpy(newNu.status,"ACTIVE");
write(fd,&newNu,sizeof(normalUser));
printf("Do you want to continue(0-No/1-Yes) ?");
scanf("%d",&choice);
while(choice){
printf("Enter the name of the normal user: ");
scanf(" %[^\n]",newNu.username);
printf("Enter the password(max 10 characters): ");
scanf(" %[^\n]",newNu.password);
newNu.userID=newUserTyp1();
newNu.balance=1000;
newNu.account_no=(newNu.userID-1000)+100000;
printf("Your userID is : %d\n",newNu.userID);
strcpy(newNu.status,"ACTIVE");
write(fd,&newNu,sizeof(normalUser));
printf("Do you want to continue(0-No/1-Yes) ?");
scanf("%d",&choice);
}
close(fd);
fd=open("ju",O_RDWR | O_CREAT,0744);
choice=1;
jointUser newJ;
printf("Enter the main name of the joint user: ");
scanf(" %[^\n]",newJ.username1);
printf("Enter the second name of the joint user: ");
scanf(" %[^\n]",newJ.username2);
printf("Enter the password(max 10 characters): ");
scanf(" %[^\n]",newJ.password);
newJ.userID=1000;
newJ.balance=1000;
newJ.account_no=(newJ.userID-1000)+100000;
printf("Your userID is : %d\n",newJ.userID);
strcpy(newJ.status,"ACTIVE");
write(fd,&newJ,sizeof(jointUser));
printf("Do you want to continue(0-No/1-Yes) ?");
scanf("%d",&choice);
while(choice){
printf("Enter the main name of the joint user: ");
scanf(" %[^\n]",newJ.username1);
printf("Enter the second name of the joint user: ");
scanf(" %[^\n]",newJ.username2);
printf("Enter the password(max 10 characters): ");
scanf(" %[^\n]",newJ.password);
newJ.userID=newUserTyp2();
newJ.balance=1000;
newJ.account_no=(newJ.userID-1000)+100000;
printf("Your userID is : %d\n",newJ.userID);
strcpy(newJ.status,"ACTIVE");
write(fd,&newJ,sizeof(jointUser));
printf("Do you want to continue(0-No/1-Yes) ?");
scanf("%d",&choice);
}
close(fd);
return 0;
}