-
Notifications
You must be signed in to change notification settings - Fork 0
/
stu_info.c
82 lines (82 loc) · 2.25 KB
/
stu_info.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
struct myst1{
char id[15];
char name[15];
}st1,temp,t1;
struct myst2{
char id[15];
time_t t;
}st2,temp1,temp2;
void Stu_info(void){
char c[15];
FILE *s,*En,*Ex,*rd;
int count1=0,count2=0;
struct tm *ptr;
printf(" Enter the student roll number: ");
scanf("%s",c);
s = fopen("student","r");
if(s==NULL){
printf("cannot open student file");
exit(0);
}
En = fopen("Entry","r");
if(En==NULL){
printf("cannot open Entry file");
exit(0);
}
Ex = fopen("Exit","r");
if(Ex==NULL){
printf("cannot open Exit file");
exit(0);
}
rd = fopen("red_stu","a");
if(rd==NULL){
printf("cannot open the red_stu file");
exit(0);
}
while(fread(&st1,sizeof(struct myst1),1,s)){
if(strcmp(c,st1.id)==0) {printf(" %s\n",st1.name);break;}
}
rewind(s);
while(fread(&st2,sizeof(struct myst2),1,Ex)){
if(strcmp(c,st2.id)==0) count1++;
}
rewind(Ex);
printf(" %s left the campus %d times\n",st1.name,count1);
while(fread(&temp1,sizeof(struct myst2),1,En)){
if(strcmp(c,temp1.id)==0){
ptr = localtime(&temp1.t);
if((ptr->tm_hour < 6) || (ptr->tm_hour >= 22)){
while(fread(&temp,sizeof(struct myst1),1,s)){
if(strcmp(c,temp.id)==0) fwrite(&temp,sizeof(struct myst1),1,rd);
}
rewind(s);
}
}
}
while(fread(&temp2,sizeof(struct myst2),1,Ex)){
if(strcmp(c,temp2.id)==0){
ptr = localtime(&temp2.t);
if((ptr->tm_hour < 6) || (ptr->tm_hour > 22)){
while(fread(&temp,sizeof(struct myst1),1,s)){
if(strcmp(c,temp.id)==0) fwrite(&temp,sizeof(struct myst1),1,rd);
}
rewind(s);
}
}
}
fclose(rd);
rd = fopen("red_stu","r");
if(rd==NULL){
printf("cannot open the red_stu2 file");
exit(0);
}
while(fread(&t1,sizeof(struct myst1),1,rd)){
if(strcmp(c,t1.id)==0) count2++;
}
printf(" %d times was arrived/left in curfew hours\n",count2);
fclose(s);fclose(En);fclose(Ex);fclose(rd);
}