-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student_history.c
84 lines (75 loc) · 2.65 KB
/
Student_history.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
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
struct myst1{
char id[15];
char name[15];
}temp;
struct myst2{
char id[15];
time_t t;
}temp1,temp2;
void studenthistory(void)
{ char c[15];
struct tm *ptr;
FILE *p1,*p2,*p3;
int enh=0,enm=0,ens=0,exh=0,exm=0,exs=0,his=0;
printf(" Enter the roll number: ");
scanf("%s",c);
p1 = fopen("student","rb+");
if(p1==NULL){
printf("\tCannot open the student file\n");
exit(0);
}
p2 = fopen("Entry","ab+");
if(p2==NULL){
printf("\tCannot open the student file\n");
}
p3 = fopen("Exit","ab+");
if(p3==NULL){
printf("\tCannot open the student file\n");
}
while(fread(&temp,sizeof(struct myst1),1,p1)){
if(strcmp(temp.id,c)==0){
printf(" Student name : %s\n",temp.name);
break;}}
printf(" Entry time list\n");
his=0;
while(fread(&temp1,sizeof(struct myst2),1,p2)){
if(strcmp(c,temp1.id)==0){
his=1;
ptr = localtime(&temp1.t);
printf(" Entry Time is: "); //print entry time
printf("%dHrs ", ptr->tm_hour);
printf("%dMnts ", ptr->tm_min);
printf("%dSecs \n", ptr->tm_sec);
enh = ptr->tm_hour;enm = ptr->tm_min;ens = ptr->tm_sec;
}
}
if (his == 0){
printf(" No History Available\n");
}
else{
printf(" Latest entry time registered: %dHrs %dMnts %dSecs \n",enh,enm,ens);
}
printf(" Exit time list\n");
his=0;
while(fread(&temp2,sizeof(struct myst2),1,p3)){
if(strcmp(c,temp2.id)==0){
his=1;
ptr = localtime(&temp2.t);
printf(" Exit Time is: ");
printf("%dHrs ", ptr->tm_hour);
printf("%dMnts ", ptr->tm_min);
printf("%dSecs \n", ptr->tm_sec);
exh = ptr->tm_hour;exm= ptr->tm_min;exs= ptr->tm_sec;
}
}
if (his == 0){
printf(" No History Available\n");
}
else{
printf(" Latest exit time registered: %dHrs %dMnts %dSecs \n",exh,exm,exs); }
fclose(p1);fclose(p2);fclose(p3);
}