/
main.c
304 lines (240 loc) · 13.9 KB
/
main.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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
void gotoxy(short int col,short int row);
struct account
{ int messchrges;
int fine;
int total;
};struct account ac;
struct existg_hostel
{
int roll;
char name[20];
char deptt[20];
char permntadd[20];
int roomno;
struct account ac;
};
struct existg_hostel eh[20];
struct new_entry
{
char name[20];
char deptt[20];
char permntadd[20];
int roomno;
int roll;
int security;
struct account ac;
};
struct new_entry nh[20];
int choice,rol,i=0,flag=0,sd,count=0;
char ch,nam[20];
FILE *fp;
int main()
{while(1)
{
system("cls");
gotoxy(28,6);
printf("HOSTEL MANAGEMENT SYSTEM");
gotoxy(25,10);
printf("--->>Press '1' for New Entry\n");
gotoxy(25,12);
printf("--->>Press '2' for Searching Existing Record\n");
gotoxy(25,14);
printf("--->>Press '3' for Deleting Record\n");
gotoxy(25,16);
printf("--->>Press '4' for Modifying Record\n");
gotoxy(25,18);
printf("--->>Press '5' to Exit\n");
gotoxy(25,20);
printf("Choice you Entered is:");
scanf("%d",&choice);
switch(choice)
{
case 1:
//new entry
system("cls");
fp=fopen("hostel_data.txt","a+");
char another='y';
int j=0;
while(fscanf(fp,"%d%s%s%s%d%d%d%d",&eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,&eh[i].roomno,&eh[i].ac.messchrges,&eh[i].ac.fine,&eh[i].ac.total)!=EOF)
{
printf("%d",count);
count++;
}
while(another=='y'||another=='Y')
{
for(j=0;j<1;j++)
{
gotoxy(25,10);
printf("Enter Name(use underscore for spaces)\t");
scanf("%s",nh[j].name);
gotoxy(25,12);
printf("Enter Department\t");
scanf("%s",nh[j].deptt);
gotoxy(25,14);
printf("Enter Permanent Address\t");
scanf("%s",nh[j].permntadd);
gotoxy(25,16);
printf("Security amount rs.2500\n");
gotoxy(25,18);
printf("Security Deposited(Press 1/0 ::Y/N)\t");
scanf("%d",&sd);
switch(sd)
{
case 1:
rewind(fp);
nh[j].roll=count+1;
nh[j].roomno=count+279;
gotoxy(25,20);
printf("Allotment Details:");
gotoxy(25,22);
printf("Roll Number %d\n",nh[j].roll);
gotoxy(25,24);
printf("Room Number %d\n",nh[j].roomno);
nh[j].ac.messchrges=0;
nh[j].ac.fine=0;
nh[j].ac.total=nh[j].ac.messchrges+nh[j].ac.fine;
fprintf(fp,"%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\n",nh[j].roll,nh[j].name,nh[j].deptt,nh[j].permntadd,nh[j].roomno,nh[j].ac.messchrges,nh[j].ac.fine,nh[j].ac.total);
gotoxy(25,26);
printf("Entry Successfully Done!!!!\n");
gotoxy(25,28);
printf("%d",j);
break;
case 0:
gotoxy(25,20);
printf("Security Pending");
gotoxy(25,22);
printf("Sorry!Roll Number and Room Number will be allotted on Receiving Security");
gotoxy(25,24);
break;
}
}
gotoxy(25,30);
printf("want to Add Another Record!\t");
fflush(stdin);
scanf("%c",&another);
system("cls");
}
fclose(fp);
printf("Press any key to Return to Main Menu");
getch();
break ;
case 2:
//searching entry
system("cls");
fp=fopen("hostel_data.txt","r");
if(fp==NULL)
exit(0);
while(another=='y'||another=='Y')
{gotoxy(25,10);
printf("Enter Roll Number:\t");
scanf("%d",&rol);
rewind(fp);
while(fscanf(fp,"%d%s%s%s%d%d%d%d",&eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,&eh[i].roomno,&eh[i].ac.messchrges,&eh[i].ac.fine,&eh[i].ac.total)!=EOF)
{ if(rol==eh[i].roll)
{ gotoxy(25,12);
printf("%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\n",eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,eh[i].roomno,eh[i].ac.messchrges,eh[i].ac.fine,eh[i].ac.total);
}
}
gotoxy(25,14);
fflush(stdin);
printf("Want to Search Another Entry(press y/n):\t");
scanf("%c",&another);
system("cls");
}
gotoxy(25,16);
printf("Press any key to Return to Main Menu");
getch();
break;
case 3:
//Delete entry
system("cls");
FILE *fn;
gotoxy(25,10);
printf("Enter roll no.:\t");
scanf("%d",&rol);
fp=fopen("hostel_data.txt","r");
fn=fopen("hostel_data2.txt","w");
while(another=='y'||another=='Y')
{
while(fscanf(fp,"%d%s%s%s%d%d%d%d",&eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,&eh[i].roomno,&eh[i].ac.messchrges,&eh[i].ac.fine,&eh[i].ac.total)!=EOF)
{ if(eh[i].roll==rol)
flag=1;
if(eh[i].roll!=rol)
{fprintf(fn,"%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\n",eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,eh[i].roomno,eh[i].ac.messchrges,eh[i].ac.fine,eh[i].ac.total);
}
}
fclose( fp);
fclose( fn);
remove( "hostel_data.txt");
rename( "hostel_data2.txt", "hostel_data.txt");
gotoxy(25,12);
if(flag==1)
printf("Entry Successfully Deleted");
if(flag==0)
printf("Not in Record!");
gotoxy(25,14);
printf("Want to Delete Another Record(press y/n):\t");
fflush(stdin);
scanf("%c",&another);
getch();
system("cls");
}
gotoxy(25,16);
printf("Press any key to Return to Main Menu");
getch();
break;
case 4:
//modify entry
system("cls");
FILE *f;
gotoxy(25,10);
printf("Enter Roll number whose Record is to be modified\t");
scanf("%d",&rol);
fp=fopen("hostel_data.txt","r");
f=fopen("hostel_data3.txt","w");
while(another=='y'||another=='Y')
{
while(fscanf(fp,"%d%s%s%s%d%d%d%d",&eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,&eh[i].roomno,&eh[i].ac.messchrges,&eh[i].ac.fine,&eh[i].ac.total)!=EOF)
{
if(eh[i].roll==rol)
{
gotoxy(25,12);
printf("Enter Mess charges");
scanf("%d",&eh[i].ac.messchrges);
gotoxy(25,14);
printf("Enter Fine");
scanf("%d",&eh[i].ac.fine);
eh[i].ac.total=eh[i].ac.messchrges+eh[i].ac.fine;
}
fprintf(f,"%d\t%s\t%s\t%s\t%d\t%d\t%d\t%d\n",eh[i].roll,eh[i].name,eh[i].deptt,eh[i].permntadd,eh[i].roomno,eh[i].ac.messchrges,eh[i].ac.fine,eh[i].ac.total);
}
fclose(fp);
fclose(f);
remove( "hostel_data.txt");
rename( "hostel_data3.txt", "hostel_data.txt");
gotoxy(25,16);
printf("Entry Successfully Modified");
gotoxy(25,18);
printf("Want to Modify Another Record(press y/n):\t");
scanf("%c",&another);
system("cls");
}
gotoxy(25,20);
printf("Press any key to Return to Main Menu");
getch();
break;
case 5:
{exit(0);
}
} }
getch();
}
void gotoxy(short int x, short int y) {
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}