-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstudent_record.c
More file actions
412 lines (334 loc) · 8.84 KB
/
student_record.c
File metadata and controls
412 lines (334 loc) · 8.84 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
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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include <sys/utsname.h>
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define WHITE "\x1b[37m"
#define RESET "\x1b[0m"
int main();
void found(char usn[15]);
struct student
{
char name[100],section,usn[10];
float fees_paid,fees_unpaid;
char phone[10];
float marks,percent;
};
struct time
{
char time_add[10];
char time_mod[10];
char time_login[10];
};
void chk_compat()
{
char os_type[] = "Linux";
struct utsname detect;
uname(&detect);
printf(YELLOW "\nPlease Wait Checking For OS Compatibility....\n" RESET);
sleep(1);
if(strcmp(detect.sysname,os_type)==0)
{
printf(WHITE "\nYou Are Using GNU/Linux\n");
printf("\nYour Operating System Is Compatible With This Script...\n" RESET);
sleep(2);
system("clear");
}
else
{
printf(RED "\nCurrently The Script Supports OS Using Linux Kernels Only.\n");
printf("\nIf You Want Me To Add Support For Other OS Contact Me @destroyerani41 On Telegram\n" RESET);
sleep(2);
exit(0);
}
}
void chk_file()
{
FILE *fr;
fr = fopen("ani.txt","rb");
if(fr==NULL)
{
printf(RED "\nFile Doesn't Exist.\nCreating The File Please Wait...\n" RESET);
sleep(2);
system("touch ani.txt");
}
else
{
printf("\nConnection Succeeded\n");
sleep(1);
}
}
void add()
{
int n,i;
FILE *fp;
struct student s[100];
printf(YELLOW "\n\t\t* * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\t\t* Student Record Management System *");
printf("\n\t\t* Project By 0x41 & 41alderson *");
printf("\n\t\t* USN: 1JB18CS015 & 1JB18CS005 *");
printf("\n\t\t* Special Thanks To: NONE *");
printf("\n\t\t* * * * * * * * * * * * * * * * * * * * * * * * * * * *" RESET);
sleep(3);
printf("\n\nPlease Wait Connecting To Database...\n");
sleep(3);
chk_file();
fp=fopen("ani.txt","ab");
printf("\nEnter No Of Students To Add: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf(RED"\n\t\tEntry For Student No %d" RESET,i+1);
printf(WHITE "\n\t--------------------------------------\n\n" RESET);
printf("usn Of The Student: ");
scanf("%s",s[i].usn);
found(s[i].usn);
printf("\nName Of The Student: ");
scanf("%s",s[i].name);
sleep(1);
printf(RED "\n\t\tEntry For %s" RESET,s[i].name);
printf(WHITE "\n\t--------------------------------------\n" RESET);
printf("\nSection Of The Student: ");
scanf(" %c",&s[i].section);
printf("\nFees Paid By The Student: ");
scanf("%f",&s[i].fees_paid);
printf("\nFees To Be Paid By The Student: ");
scanf("%f",&s[i].fees_unpaid);
printf("\nPhone-Number Of The Student: ");
scanf("%s",s[i].phone);
while(strlen(s[i].phone)!=10)
{
printf(RED "\nPhone Number Length Is Not 10 Digits.\nPlease Re-Enter\n" RESET);
sleep(1);
printf("\nPhone-Number Of The Student: ");
scanf("%s",s[i].phone);
while(1)
{
break;
}
}
printf("\nTotal Marks Scored By The Student: ");
scanf("%f",&s[i].marks);
printf("\nTotal Percentage: ");
scanf("%f",&s[i].percent);
fwrite(&s,sizeof(s),1,fp);
printf(YELLOW "\nSTUDENT RECORD FOR %s ADDED SUCCESSFULLY\n" RESET,s[i].name);
fclose(fp);
sleep(2);
printf("\nReturning To Main Menu.\n");
system("clear");
}
}
void found(char usn[15])
{
struct student found;
FILE *fr;
int stu_found=0;
fr=fopen("ani.txt","rb");
while(fread(&found,sizeof(found),1,fr) == 1)
{
if(strcmp(usn,found.usn) == 0)
{
stu_found = 1;
break;
}
}
if(stu_found == 1)
{
printf(RED "\nStudent Record Of %s Is Already Present\n" RESET,usn);
sleep(2);
system("clear");
main();
}
}
void search()
{
char search_usn[15];
FILE *fr;
int stu_found = 0;
struct student info;
char again;
printf("\nPease Wait Connecting To DB.\n");
sleep(1);
fr=fopen("ani.txt","rb");
if(fr==NULL)
{
printf(RED "\nFile Note Found.\n(Or) \nFile Is Not Placed In Required Path\n." RESET);
sleep(2);
main();
}
printf("\nEnter USN Of The Student To View Data: ");
scanf("%s",search_usn);
while(fread(&info,sizeof(info),1,fr) == 1)
{
if(strcmp(search_usn,info.usn) == 0)
{
stu_found = 1;
break;
}
}
if(stu_found == 1)
{
sleep(2);
printf(WHITE "\nStudent Record Of '%s' Found\n\n",info.usn);
printf("Student-USN: %s\n",info.usn);
printf("Student-Name: %s\n",info.name);
printf("Section: %c\n",info.section);
printf("Fees-Paid: %f\n",info.fees_paid);
printf("Fees-To-Be-Paid: %f\n",info.fees_unpaid);
printf("Marks Obtained: %f\n",info.marks);
printf("Total Percentage: %f\n",info.percent);
printf("Phone No: %s\n",info.phone);
sleep(2);
}
else
{
printf(RED "\nSorry, No record found in the database" RESET);
sleep(2);
}
printf(RESET "\nDo You Want To Perform Another Search[y/n]: ");
scanf(" %c",&again);
if(again=='y')
{
search();
}
else if (again=='n')
{
system("clear");
main();
}
else
{
printf(RED "\nUnknown Option Chosen.\nTaking You Back To Main Menu..\n" RESET);
sleep(2);
system("clear");
main();
}
}
void display_all()
{
FILE *fp;
char display_data,s;
fp= fopen("ani.txt","rb+");
display_data = fgetc(fp);
printf(WHITE "\n\tDisplaying All Students Data\n" RESET);
while(display_data!=EOF)
{
printf("%c",display_data);
display_data = fgetc(fp);
}
fclose(fp);
sleep(1);
printf("\n\nPress Any Key To Continue..\n");
scanf("%c",&s);
getchar();
}
void delete_stu()
{
char usn[15],k;
FILE *fp, *temp;
struct student ss;
char cmd[100];
printf("\nEnter USN Of The Student To Delete: ");
scanf("%s",usn);
fp = fopen("ani.txt","rb");
temp = fopen("temp_ani.txt", "wb");
if(temp!=NULL)
{
printf(YELLOW "\nPlease Wait Performing Necessary Operations\n" RESET);
system("touch temp_ani.txt");
sleep(2);
printf(YELLOW "\nCreating A Back-Up File Please Wait..\n" RESET);
system("cat ani.txt > ani.txt.bk");
sleep(1);
printf(YELLOW "\nBack-Up File Created Successfully As ani.txt.bk\n" RESET);
fflush(stdin);
}
else if(temp==NULL)
{
printf("....");
fflush(stdin);
}
else
{
printf(RED "Unknown Error Crashed The Current Operation\n" RESET);
sleep(2);
printf("\nReturning To Main Menu\n");
fflush(stdin);
}
while(fread(&ss, sizeof(ss),1,fp)==1)
{
if(strcmp(usn,ss.usn) == 0)
{
fwrite(&ss,sizeof(ss),1,temp);
}
}
fclose(fp);
fclose(temp);
remove("ani.txt");
rename("temp_ani.txt","ani.txt");
printf("\nStudent Data Of %s Has Been Deleted Successfully\n",usn);
sleep(1);
printf("\n\nPress Any Key To Continue..\n");
scanf("%c",&k);
getchar();
}
int main()
{
int opt;
system("clear");
chk_compat();
printf(YELLOW "\n\t\t* * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("\n\t\t* Student Record Management System *");
printf("\n\t\t* Project By 0x41 & 41alderson *");
printf("\n\t\t* USN: 1JB18CS015 & 1JB18CS005 *");
printf("\n\t\t* Special Thanks To: NONE *");
printf("\n\t\t* * * * * * * * * * * * * * * * * * * * * * * * * * * *" RESET);
sleep(3);
printf(RED "\n\t\t\t\tMenu\n" RESET);
printf(BLUE "\n1.Add Student.\n2.Search Student Data\n3.Delete Student Data.\n4.Display All Student Data.\n5.Exit" RESET);
printf(RED "\n\nYour Selection: " RESET);
scanf("%d",&opt);
switch(opt)
{
case 1:printf("\nYou Selected Add Student.\n");
system("echo Student Data Was Added @ `date` | cat >>log");
add();
printf("\nReturning To Main Menu.\n");
sleep(2);
main();
case 2:printf("\nYou Selected Display Student Data.\n");
system("echo Student Data Was Searched @ `date` | cat >>log");
search();
printf("\nReturning To Main Menu.\n");
sleep(2);
main();
case 3:printf("\nYou Selected Remove Student.\n");
system("echo Student Data Was Deleted @ `date` | cat >>log");
delete_stu();
printf("\nReturning To Main Menu.\n");
sleep(2);
main();
case 4:printf("\nYou Selected Dislpay All Student Data.\n");
system("echo Student Data Was Displayed @ `date` | cat >>log");
display_all();
printf("\nReturning To Main Menu.\n");
sleep(2);
main();
case 5:printf("\nQuitting The Interface\n");
system("echo User/Admin Quit The Script @ `date` | cat >>log");
sleep(3);
exit(1);
default:printf("\nUnknown Option Selected.\n");
system("echo User/Admin Chose Unknown Option @ `date` | cat >>log");
break;
main();
}
}