-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhostel_manage.c
425 lines (376 loc) · 14.5 KB
/
hostel_manage.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i,j;
int main_exit;
void menu();
void closer();
struct date{
int month,day,year;
};
struct {
char name[60];
int age;
char city[60];
char mail_id[30];
char room_no[8];
char father_name[60];
int father_phone;
int phone;
char hostel_name[6];
char roll_no[10];
struct date dob;
}add,upd,check,rem,sort;
void new_entry()
{
int choice;
FILE *ptr;
ptr=fopen("record.dat","a+");
roll_no:
printf("\t\t\t\xB2\xB2\xB2 ADD STUDENTS DATA \xB2\xB2\xB2\xB2");
printf("\nEnter your roll number:");
scanf("%s",check.roll_no);
while(fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
{
if (check.roll_no==add.roll_no)
{printf("Students roll no. already in use!");
goto roll_no;
}
}
strcpy(add.roll_no,check.roll_no);
printf("\nEnter the name:");
scanf("%s",add.name);
printf("\nEnter the date of birth(mm/dd/yyyy):");
scanf("%d/%d/%d",&add.dob.month,&add.dob.day,&add.dob.year);
printf("\nEnter the age:");
scanf("%d",&add.age);
printf("\nEnter the city:");
scanf("%s",add.city);
printf("\nEnter the phone number: ");
scanf("%d",&add.phone);
printf("\n Enter your email id :");
scanf("%s",add.mail_id);
printf("\n Enter your Father's name:");
scanf("%s",add.father_name);
printf("\n Enter your Father's phone no.:");
scanf("%d",&add.father_phone);
printf("\n Enter your room no.:");
scanf("%s",add.room_no);
printf("\n Enter your hostel name from BH-1, BH-2, BH-3, GH-1 :");
scanf("%s",add.hostel_name);
fprintf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
fclose(ptr);
printf("\nStudent added successfully!");
add_invalid:
printf("\n\n\n\t\tEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else if(main_exit==0)
closer();
else
{
printf("\nInvalid!\a");
goto add_invalid;
}
}
void view_list()
{
FILE *view;
view=fopen("record.dat","r");
int test=0;
printf("\nROLL NO.\tNAME\t\t\tcity\t\t\tPHONE\n");
while(fscanf(view,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
{
printf("\n%8s\t %10s\t\t\t %10s\t\t %d",add.roll_no,add.name,add.city,add.phone);
test++;
}
fclose(view);
if (test==0)
{
printf("\nNO RECORDS!!\n");}
view_list_invalid:
printf("\n\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else if(main_exit==0)
closer();
else
{
printf("\nInvalid!\a");
goto view_list_invalid;
}
}
void edit(void)
{
int choice,test=0;
FILE *old,*newrec;
old=fopen("record.dat","r");
newrec=fopen("new.dat","w");
printf("\nEnter the roll no. of the student whose info you want to change:");
scanf("%s",upd.roll_no);
while(fscanf(old,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
{
if (add.roll_no==upd.roll_no)
{ test=1;
printf("\nWhich information do you want to change?\n1.Room no.\n2.Phone\n\nEnter your choice(1 for room no. and 2 for phone ):");
scanf("%d",&choice);
if(choice==1)
{printf("Enter the new room no.:");
scanf("%s",upd.room_no);
fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, upd.room_no, add.hostel_name);
printf("Changes saved!");
}
else if(choice==2)
{
printf("Enter the new phone number:");
scanf("%d",&upd.phone);
fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, upd.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
printf("Changes saved!");
}
}
else
fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
}
fclose(old);
fclose(newrec);
remove("record.dat");
rename("new.dat","record.dat");
if(test!=1)
{
printf("\nRecord not found!!\a\a\a");
edit_invalid:
printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else if (main_exit==2)
closer();
else if(main_exit==0)
edit();
else
{printf("\nInvalid!\a");
goto edit_invalid;}
}
else
{printf("\n\n\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else
closer();
}
}
void erase(void)
{
FILE *old,*newrec;
int test=0;
old=fopen("record.dat","r");
newrec=fopen("new.dat","w");
printf("Enter the roll np. of student whose data you want to delete:");
scanf("%s",rem.roll_no);
while (fscanf(old,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
{
if(add.roll_no!=rem.roll_no)
fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
else
{test++;
printf("\nRecord deleted successfully!\n");
}
}
fclose(old);
fclose(newrec);
remove("record.dat");
rename("new.dat","record.dat");
if(test==0)
{
printf("\nRecord not found!!\a\a\a");
erase_invalid:
printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else if (main_exit==2)
closer();
else if(main_exit==0)
erase();
else
{printf("\nInvalid!\a");
goto erase_invalid;}
}
else
{printf("\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else
closer();
}
}
void see(void)
{
FILE *ptr;
int test=0,rate;
int choice;
float time;
float intrst;
ptr=fopen("record.dat","r");
printf("Do you want to check by\n1.Roll no\n2.Name\nEnter your choice:");
scanf("%d",&choice);
if (choice==1)
{ printf("Enter the roll number:");
scanf("%s",check.roll_no);
while (fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
{
if(add.roll_no==check.roll_no)
{
test=1;
printf("\nROLL NO.:%s\nName:%s \nDOB:%d/%d/%d \nAge:%d \ncity:%s \nPhone number:%d \nE-Mail id:%s \nFather's name:%s \n Father's Phone No.:%d \nRoom No:%s \nHostel:%s \n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
}
}
}
else if (choice==2)
{ printf("Enter the name:");
scanf("%s",check.name);
while (fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
{
if(strcmp(add.name,check.name)==0)
{
test=1;
printf("\nROLL NO.:%s\nName:%s \nDOB:%d/%d/%d \nAge:%d \ncity:%s \nPhone number:%d \nE-Mail id:%s \nFather's name:%s \n Father's Phone No.:%d \nRoom No:%s \nHostel:%s \n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
}
}
}
fclose(ptr);
if(test!=1)
{
printf("\nRecord not found!!\a\a\a");
see_invalid:
printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else if (main_exit==2)
closer();
else if(main_exit==0)
see();
else
{
printf("\nInvalid!\a");
goto see_invalid;}
}
else
{printf("\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);}
if (main_exit==1)
{
menu();
}
else
{
closer();
}
}
void sorter(void)
{
int choice;
printf("Enter year choice:\n\n\t\t1. BH-1 \n\t\t2. BH-2 \n\t\t3. BH-3 \n\t\t4. GH-1 \n\n");
scanf("%d",&choice);
FILE *fp, *sort1, *sort2, *sort3, *sort4;
fp=fopen("record.dat","r");
int test=0;
while(fscanf(fp,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",sort.roll_no, sort.name, &sort.dob.month, &sort.dob.day, &sort.dob.year, &sort.age, sort.city, &sort.phone, sort.mail_id, sort.father_name, &sort.father_phone, sort.room_no, sort.hostel_name)!=EOF)
{
if(choice==1 && strcmp(sort.hostel_name,"BH-1")==0)
{
sort1=fopen("sortBH-1.dat","a+");
printf("\t\tFollowing are students of BH-1 hostel:");
printf("\n\tROLL NO.\tROOM NO.\tNAME\n");
printf("\n\t%8s\t %8s\t %s", sort.roll_no, sort.room_no, sort.name);
test++;
fprintf(sort1, "%s %s %s\n", sort.roll_no, sort.room_no, sort.name);
fclose(sort1);
}
else if(choice==2 && strcmp(sort.hostel_name,"BH-2")==0)
{
sort2=fopen("sortBH-2.dat","a+");
printf("\t\tFollowing are students of BH-2 hostel:");
printf("\n\tROLL NO.\tROOM NO.\tNAME\n");
printf("\n\t%8s\t %8s\t %s", sort.roll_no, sort.room_no, sort.name);
test++;
fprintf(sort2, "%s %s %s\n", sort.roll_no, sort.room_no, sort.name);
fclose(sort2);
}
else if(choice==3 && strcmp(sort.hostel_name,"BH-3")==0)
{
sort3=fopen("sortBH-3.dat","a+");
printf("\t\tFollowing are students of BH-3 hostel:");
printf("\n\tROLL NO.\tROOM NO.\tNAME\n");
printf("\n\t%8s\t %8s\t %s", sort.roll_no, sort.room_no, sort.name);
test++;
fprintf(sort3, "%s %s %s\n", sort.roll_no, sort.room_no, sort.name);
fclose(sort3);
}
else if(choice==4 && strcmp(sort.hostel_name,"GH-1")==0)
{
sort4=fopen("sortBH-4.dat","a+");
printf("\t\tFollowing are students of GH-1 hostel:");
printf("\n\tROLL NO.\tROOM NO.\tNAME\n");
printf("\n\t%8s\t %8s\t %s", sort.roll_no, sort.room_no, sort.name);
test++;
fprintf(sort4, "%s %s %s\n", sort.roll_no, sort.room_no, sort.name);
fclose(sort4);
}
}
fclose(fp);
if (test==0)
{
printf("\nNO RECORDS!!\n");}
sort_list_invalid:
printf("\n\nEnter 1 to go to the main menu and 0 to exit:");
scanf("%d",&main_exit);
if (main_exit==1)
menu();
else if(main_exit==0)
closer();
else
{
printf("\nInvalid!\a");
goto sort_list_invalid;
}
}
void closer()
{
printf("\n\n\n\nDeveloped by Punit Agarwal\n\n\n");
}
void menu(void)
{ int choice;
system("color 9");
printf("\n\n\t\t\tHOSTEL DATA MANAGEMENT SYSTEM");
printf("\n\n\n\t\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO THE MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2");
printf("\n\n\t\t1.Enter new Student's data\n\t\t2.Update information of existing account\n\t\t3.Check the details of existing account\n\t\t4.View all Students of a particlar Hostel\n\t\t5.Removing existing account\n\t\t6.View all students list\n\t\t7.Exit\n\n\n\n\n\t\t Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:new_entry();
break;
case 2:edit();
break;
case 3:see();
break;
case 4:sorter();
break;
case 5:erase();
break;
case 6:view_list();
break;
case 7:closer();
break;
}
}
int main()
{
menu();
return 0;
}