Skip to content

Commit

Permalink
is
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghazi Shazan Ahmad committed Jul 31, 2020
0 parents commit 416d781
Show file tree
Hide file tree
Showing 24 changed files with 733 additions and 0 deletions.
103 changes: 103 additions & 0 deletions Entry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
#include"check.h"
//Entry file to register the entry time of a student
struct myst2{
char id[15];
time_t t;
}st1,st2;

struct myst3{
char id[15];
int checker;
}st3;

struct myst4{
char id[15];
}st4;

void Entrytime(void){

int k=0; //flag to check if student is registered or not
char b[15];
char c[15];
FILE *En,*ch,*wa;
ch = fopen("status","ab+");

if(ch==NULL){
printf("Cannot open Entry file");
exit(0);
}

printf(" Enter the student ID number: ");
scanf("%s",c);
strcpy(st1.id,c);

if (check(c)==1){
while(fread(&st3,sizeof(struct myst3),1,ch))
{
if (strcmp(st3.id,st1.id)==0){
k=st3.checker;
}
}
fclose(ch);

if (k==1){
En = fopen("Entry","ab+");
ch = fopen("status","ab+");
while(fread(&st3,sizeof(struct myst3),1,ch))
{
if (strcmp(st3.id,st1.id)==0){
st3.checker=0;
fwrite(&st3,sizeof(struct myst3),1,ch);
}
}
st1.t = time(NULL);
fwrite(&st1,sizeof(struct myst2),1,En);
fclose(En);fclose(ch);
}

else {
En = fopen("Entry","ab+");
ch = fopen("status","ab+");
printf(" Warning previous entry time not registered\n");
printf(" Do you want to continue (Y/N)?: ");
scanf("%s",b);
if (strcmp(b,"Y") == 0)
{
wa = fopen("warnings","ab+");
strcpy(st4.id,c);
fwrite(&st4,sizeof(struct myst4),1,wa);
fclose(wa);
strcpy(st2.id,c);
st2.t=time(NULL);
if(En==NULL){
printf("\tCannot open the Entry file\n");
exit(0);
}
while(fread(&st3,sizeof(struct myst3),1,ch))
{
if (strcmp(st3.id,st1.id)==0){
st3.checker=0;
fwrite(&st3,sizeof(struct myst3),1,ch);
}
}
fwrite(&st2, sizeof(struct myst2),1,En);
}
else if (strcmp(b,"N") == 0){
printf(" Entry time not registered\n");
}
else
{
printf(" Unrecognised command\n");
}
fclose(En);fclose(ch);
}
}

else if (check(c)==0){
printf(" %s not registered\n",c);
}
}
1 change: 1 addition & 0 deletions Entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void Entrytime(void);
98 changes: 98 additions & 0 deletions Exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include"check.h"
//file to register the exit of a student
struct myst2{
char id[15];
time_t t;
}st1,st2;

struct myst3{
char id[15];
int checker;
}st3;

struct myst4{
char id[15];
}st4;

void Exittime(void){
int k=1;
char b[15];
char c[15];
FILE *Ex,*ch,*wa;
ch = fopen("status","ab+");
if(ch==NULL){
printf("Cannot open Exit file");
exit(0);
}

printf(" Enter the student ID number: ");
scanf("%s",c);
strcpy(st1.id,c); //copy the entered roll number into the structure
if (check(c)==1){
while(fread(&st3,sizeof(struct myst3),1,ch))
{
if (strcmp(st3.id,st1.id)==0){
k=st3.checker;
}
}
fclose(ch);

if (k==0){
Ex = fopen("Exit","ab+");
ch = fopen("status","ab+");
while(fread(&st3,sizeof(struct myst3),1,ch)) //register exit if student is in the database
{
if (strcmp(st3.id,st1.id)==0){
st3.checker=1;
fwrite(&st3,sizeof(struct myst3),1,ch);
}
}
st1.t = time(NULL);
fwrite(&st1,sizeof(struct myst2),1,Ex);
fclose(ch);fclose(Ex);
}
else {
Ex = fopen("Exit","ab+");
ch = fopen("status","ab+");
printf(" Warning previous entry time not registered\n"); //warning if student did not make an entry before exit
printf(" Do you want to continue (Y/N)? : "); //by default all registered students are considered in the campus
scanf("%s",b);
if (strcmp(b,"Y")==0)
{
wa = fopen("warnings","ab+");
strcpy(st4.id,c);
fwrite(&st4,sizeof(struct myst4),1,wa);
fclose(wa);
strcpy(st2.id,c);
st2.t=time(NULL);
if(Ex==NULL){
printf("\tCannot open the Entry file\n");
exit(0);
}
while(fread(&st3,sizeof(struct myst3),1,ch))
{
if (strcmp(st3.id,st1.id)==0){
st3.checker=1;
fwrite(&st3,sizeof(struct myst3),1,ch);
}
}
fwrite(&st2, sizeof(struct myst2),1,Ex);
}
else if (strcmp(b,"N")==0){
printf(" Exit time not registered\n");
}
else
{
printf(" Unrecognised command\n"); //in case of unnecessary commands
}
fclose(Ex);
fclose(ch);
}
}
else if(check(c)==0){
printf(" student not registered\n");}
}
1 change: 1 addition & 0 deletions Exit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void Exittime(void);
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#-*-Makefile-*

main: main.o add_student.o Entry.o Exit.o Student_status.o stu_info.o Student_history.o Student_list.o check.o warnings.o display.o
gcc main.o add_student.o Entry.o Exit.o Student_status.o stu_info.o Student_history.o Student_list.o check.o warnings.o display.o -o main
main.o: main.c add_student.h Entry.h Exit.h Student_status.h stu_info.h Student_history.h Student_list.h check.h warnings.h display.h
gcc -c main.c
add_student.o: add_student.c
gcc -c add_student.c
Entry.o: Entry.c
gcc -c Entry.c
Exit.o: Exit.c
gcc -c Exit.c
Student_status.o: Student_status.c
gcc -c Student_status.c
stu_info.o: stu_info.c
gcc -c stu_info.c
Student_list.o: Student_list.c
gcc -c Student_list.c
Student_history.o: Student_history.c
gcc -c Student_history.c
check.o: check.c
gcc -c check.c
warnings.o: warnings.c
gcc -c warnings.c
display.o: display.c
gcc -c display.c
clean:
rm *.o main
84 changes: 84 additions & 0 deletions Student_history.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
1 change: 1 addition & 0 deletions Student_history.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void studenthistory(void);
17 changes: 17 additions & 0 deletions Student_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<stdlib.h>
struct myst1{
char id[15];
char name[15];
}st1;
void studentlist(void){
FILE *p1;
p1 = fopen("student","r");
if(p1==NULL){
printf("cannot open student file");
exit(0);
}
//prints the list of registered students from students database
while(fread(&st1,sizeof(struct myst1),1,p1)) printf(" Student ID : %s Student name : %s\n",st1.id,st1.name);
fclose(p1);
}
1 change: 1 addition & 0 deletions Student_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void studentlist(void);
52 changes: 52 additions & 0 deletions Student_status.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include"check.h"

struct myst3{
char id[15];
int checker;
}st3;

struct myst1{
char id[15];
char name[15];
}st1;

void Student_status(void){
int k;
char c[15],b[15];
FILE *p1,*p2;
printf(" Enter the student ID number:");
scanf("%s",c);
if(check(c)==1){ //flag to check if student is registered or not
p2 = fopen("student","r");
p1 = fopen("status","r");

while(fread(&st1,sizeof(struct myst1),1,p2)){ //look for the registered name in registered student database
if (strcmp(st1.id,c)==0){
strcpy(b,st1.name);break;}}
while(fread(&st3,sizeof(struct myst3),1,p1)){
if(strcmp(st3.id,c)==0){
k = st3.checker;
}
}

if (k==1)
{
printf(" %s is not in the campus\n",b);
}

else if(k==0)
{
printf(" %s is in the campus\n",b);
}

fclose(p1);fclose(p2);
}

else if (check(c)==0){
printf(" Student not registered\n");
}
}
1 change: 1 addition & 0 deletions Student_status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void Student_status(void);
Loading

0 comments on commit 416d781

Please sign in to comment.