-
Notifications
You must be signed in to change notification settings - Fork 1
/
Student_Record_Management.c
303 lines (295 loc) · 6.64 KB
/
Student_Record_Management.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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<string.h>
void gotoxy(int ,int );
void menu();
void add();
void view();
void search();
void modify();
void deleterec();
struct student
{
char name[20];
char mobile[10];
int regno;
char section[20];
char branch[20];
};
int main()
{
gotoxy(15,7);
printf("<--:Student Record Management System:-->\n");
gotoxy(22,10);
printf("Press any key to continue.");
getch();
menu();
return 0;
}
void menu()
{
int choice;
system("cls");
gotoxy(10,3);
printf("<--:MENU:-->");
gotoxy(10,5);
printf("Enter appropriate number to perform following task.");
gotoxy(10,7);
printf("1 : Add Record.");
gotoxy(10,8);
printf("2 : View Record.");
gotoxy(10,9);
printf("3 : Search Record.");
gotoxy(10,10);
printf("4 : Modify Record.");
gotoxy(10,11);
printf("5 : Delete.");
gotoxy(10,12);
printf("6 : Exit.");
gotoxy(10,15);
printf("Enter your choice.");
scanf("%d",&choice);
switch(choice)
{
case 1:
add();
break;
case 2:
view();
break;
case 3:
search();
break;
case 4:
modify();
break;
case 5:
deleterec();
break;
case 6:
exit(1);
break;
default:
gotoxy(10,17);
printf("Invalid Choice.");
}
}
void add()
{
FILE *fp;
struct student std;
char another ='y';
system("cls");
fp = fopen("record.txt","ab+");
if(fp == NULL){
gotoxy(10,5);
printf("Error opening file");
exit(1);
}
fflush(stdin);
while(another == 'y')
{
gotoxy(10,3);
printf("<--:ADD RECORD:-->");
gotoxy(10,5);
printf("Enter details of student.");
gotoxy(10,7);
printf("Enter Name : ");
gets(std.name);
gotoxy(10,8);
printf("Enter Mobile Number : ");
gets(std.mobile);
gotoxy(10,9);
printf("Enter Reg No : ");
scanf("%d",&std.regno);
fflush(stdin);
gotoxy(10,10);
printf("Enter Section : ");
gets(std.section);
gotoxy(10,11);
printf("Enter Branch : ");
gets(std.branch);
fwrite(&std,sizeof(std),1,fp);
gotoxy(10,15);
printf("Want to add of another record? Then press 'y' else 'n'.");
fflush(stdin);
another = getch();
system("cls");
fflush(stdin);
}
fclose(fp);
gotoxy(10,18);
printf("Press any key to continue.");
getch();
menu();
}
void view()
{
FILE *fp;
int i=1,j;
struct student std;
system("cls");
gotoxy(10,3);
printf("<--:VIEW RECORD:-->");
gotoxy(10,5);
printf("S.No Name of Student Mobile No Reg No Section Branch");
gotoxy(10,6);
printf("--------------------------------------------------------------------");
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,8);
printf("Error opening file.");
exit(1);
}
j=8;
while(fread(&std,sizeof(std),1,fp) == 1){
gotoxy(10,j);
printf("%-7d%-22s%-14s%-9d%-12s%-12s",i,std.name,std.mobile,std.regno,std.section,std.branch);
i++;
j++;
}
fclose(fp);
gotoxy(10,j+3);
printf("Press any key to continue.");
getch();
menu();
}
void search()
{
FILE *fp;
struct student std;
char stname[20];
system("cls");
gotoxy(10,3);
printf("<--:SEARCH RECORD:-->");
gotoxy(10,5);
printf("Enter name of student : ");
fflush(stdin);
gets(stname);
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
while(fread(&std,sizeof(std),1,fp ) == 1){
if(strcmp(stname,std.name) == 0){
gotoxy(10,8);
printf("Name : %s",std.name);
gotoxy(10,9);
printf("Mobile Number : %s",std.mobile);
gotoxy(10,10);
printf("Reg No : %d",std.regno);
gotoxy(10,11);
printf("Section : %s",std.section);
gotoxy(10,12);
printf("Branch : %s",std.branch);
}
else {
gotoxy(10,8);
printf("Record does not exist");
}
}
fclose(fp);
gotoxy(10,16);
printf("Press any key to continue.");
getch();
menu();
}
void modify()
{
char stname[20];
FILE *fp;
struct student std;
system("cls");
gotoxy(10,3);
printf("<--:MODIFY RECORD:-->");
gotoxy(10,5);
printf("Enter name of student to modify: ");
fflush(stdin);
gets(stname);
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
rewind(fp);
fflush(stdin);
while(fread(&std,sizeof(std),1,fp) == 1)
{
if(strcmp(stname,std.name) == 0){
gotoxy(10,7);
printf("Enter name: ");
gets(std.name);
gotoxy(10,8);
printf("Enter mobile number : ");
gets(std.mobile);
gotoxy(10,9);
printf("Enter reg no : ");
scanf("%d",&std.regno);
gotoxy(10,10);
printf("Enter Section : ");
fflush(stdin);
gets(std.section);
gotoxy(10,11);
printf("Enter Branch : ");
fflush(stdin);
gets(std.branch);
fseek(fp ,-sizeof(std),SEEK_CUR);
fwrite(&std,sizeof(std),1,fp);
break;
}
}
fclose(fp);
gotoxy(10,16);
printf("Press any key to continue.");
getch();
menu();
}
void deleterec()
{
char stname[20];
FILE *fp,*ft;
struct student std;
system("cls");
gotoxy(10,3);
printf("<--:DELETE RECORD:-->");
gotoxy(10,5);
printf("Enter name of student to delete record : ");
fflush(stdin);
gets(stname);
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
ft = fopen("temp.txt","wb+");
if(ft == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
while(fread(&std,sizeof(std),1,fp) == 1){
if(strcmp(stname,std.name)!=0)
fwrite(&std,sizeof(std),1,ft);
}
fclose(fp);
fclose(ft);
remove("record.txt");
rename("temp.txt","record.txt");
gotoxy(10,10);
printf("Press any key to continue.");
getch();
menu();
}
void gotoxy(int x,int y)
{
COORD c;
c.X=x;
c.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}