diff --git a/Entry.c b/Entry.c new file mode 100644 index 0000000..4101311 --- /dev/null +++ b/Entry.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#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); + } +} diff --git a/Entry.h b/Entry.h new file mode 100644 index 0000000..ca62ec7 --- /dev/null +++ b/Entry.h @@ -0,0 +1 @@ +void Entrytime(void); diff --git a/Exit.c b/Exit.c new file mode 100644 index 0000000..18187db --- /dev/null +++ b/Exit.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#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");} +} diff --git a/Exit.h b/Exit.h new file mode 100644 index 0000000..55707c8 --- /dev/null +++ b/Exit.h @@ -0,0 +1 @@ +void Exittime(void); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d22feb1 --- /dev/null +++ b/Makefile @@ -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 diff --git a/Student_history.c b/Student_history.c new file mode 100644 index 0000000..f7424a4 --- /dev/null +++ b/Student_history.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include + +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); +} diff --git a/Student_history.h b/Student_history.h new file mode 100644 index 0000000..c6ee327 --- /dev/null +++ b/Student_history.h @@ -0,0 +1 @@ +void studenthistory(void); diff --git a/Student_list.c b/Student_list.c new file mode 100644 index 0000000..27ce740 --- /dev/null +++ b/Student_list.c @@ -0,0 +1,17 @@ +#include +#include +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); +} diff --git a/Student_list.h b/Student_list.h new file mode 100644 index 0000000..2c51f8f --- /dev/null +++ b/Student_list.h @@ -0,0 +1 @@ +void studentlist(void); diff --git a/Student_status.c b/Student_status.c new file mode 100644 index 0000000..a226f13 --- /dev/null +++ b/Student_status.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#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"); + } +} diff --git a/Student_status.h b/Student_status.h new file mode 100644 index 0000000..81daa86 --- /dev/null +++ b/Student_status.h @@ -0,0 +1 @@ +void Student_status(void); diff --git a/add_student.c b/add_student.c new file mode 100644 index 0000000..535353d --- /dev/null +++ b/add_student.c @@ -0,0 +1,50 @@ +#include +#include +#include +struct myst1{ +char id[15]; +char name[15]; +}st1,st2; + +struct myst3{ +char id[15]; +int checker; +}st3; + +void Add_student(void){ + FILE *s,*ch; + s = fopen("student","ab+"); + if(s==NULL){ + printf("Cannot open the student file"); + exit(0); + } //student registration function + + ch = fopen("status","ab+"); + if(ch==NULL){ + printf("Cannot open the student file"); + exit(0); + } + printf(" Enter student ID number: "); + int flag=0; + scanf("%s",st1.id); + while(fread(&st2,sizeof(struct myst1),1,s)) //read string and register in the structure than write in the database + { + if (strcmp(st1.id,st2.id)==0) + { + flag=1; + printf(" ID Number already exists\n"); + break; + } + } + if (flag==0) //check if name is already registered or not + { + printf(" Enter the student name: "); + scanf(" %[^\n]s",st1.name); + printf("\n"); + fwrite(&st1,sizeof(struct myst1),1,s); + } + strcpy(st3.id,st1.id); + st3.checker=0; + fwrite(&st3,sizeof(struct myst3),1,ch); + fclose(s);fclose(ch); +} diff --git a/add_student.h b/add_student.h new file mode 100644 index 0000000..8ce08d6 --- /dev/null +++ b/add_student.h @@ -0,0 +1 @@ +void Add_student(void); diff --git a/check.c b/check.c new file mode 100644 index 0000000..aa36dd5 --- /dev/null +++ b/check.c @@ -0,0 +1,30 @@ +#include +#include +#include + +extern struct myst1{ + char id[15]; + char name[15]; +}st1; + +int check(char c[]){ + FILE *p1; + struct myst1 st1; + p1 = fopen("student","ab+"); //open student database + if (p1==NULL){ + printf("Cannot open the student file\n"); //if file cannot be opened + exit(0); + } + + while(fread(&st1,sizeof(struct myst1),1,p1)) //check if the the given student is already registered or not + { + if (strcmp(st1.id,c)==0) //returns zero if not registered + { + fclose(p1); + return 1; + } + } + fclose(p1); + + return 0; +} diff --git a/check.h b/check.h new file mode 100644 index 0000000..3239a09 --- /dev/null +++ b/check.h @@ -0,0 +1 @@ +int check(char[]); diff --git a/display.c b/display.c new file mode 100644 index 0000000..3a065a9 --- /dev/null +++ b/display.c @@ -0,0 +1,23 @@ +#include +#include + +void display(void) //to display the options menu given in display.txt if we enter number 10 +{ + FILE *fp; + fp = fopen("display.txt","r"); //open file in readonly MODE + char c; + + if (fp == NULL) + { + printf("Cannot open the file\n"); + exit(0); + } + c = fgetc(fp); + + while (c!=EOF) + { + printf("%c",c); //print till the end of file + c = fgetc(fp); + } + fclose(fp); +} diff --git a/display.h b/display.h new file mode 100644 index 0000000..20834b0 --- /dev/null +++ b/display.h @@ -0,0 +1 @@ +void display(void); diff --git a/display.txt b/display.txt new file mode 100644 index 0000000..8cd7b18 --- /dev/null +++ b/display.txt @@ -0,0 +1,13 @@ + ******************************* + 1.Add student + 2.Add student entry time + 3.Add student exit time + 4.Student status + 5.Student details + 6.student history + 7.student list + 8.Student registration check + 9.No.of warnings + 10.Display all options + 0.QUIT + ******************************* diff --git a/main.c b/main.c new file mode 100644 index 0000000..af48aed --- /dev/null +++ b/main.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include"warnings.h" +#include"add_student.h" +#include"Entry.h" +#include"Exit.h" +#include"Student_status.h" +#include"stu_info.h" +#include"Student_history.h" +#include"Student_list.h" +#include"check.h" +#include"display.h" + +struct myst1{ +char id[15]; +char name[15]; +}; + +struct myst2{ +char id[15]; +time_t t; +}; + +struct myst3{ +char id[15]; +int checker; +}; + +struct myst4{ +char id[15]; +}; + +int main(){ + int s; + char c[15]; + int p; + + system("clear"); + printf("\t\t MY GATE \t\t\n"); + printf("\t******************************\n"); + printf("\t 1.Add student\n"); + printf("\t 2.Add student entry time\n"); + printf("\t 3.Add student exit time\n"); + printf("\t 4.Student status\n"); + printf("\t 5.Student details\n"); + printf("\t 6.student history\n"); + printf("\t 7.student list\n"); + printf("\t 8.Student registration check\n"); + printf("\t 9.No.of warnings\n"); + printf("\t 10.display all options\n"); + printf("\t 0.QUIT\n"); + printf("\t******************************\n"); + + for(;s!=0;){ + printf("Enter your option : "); + scanf("%d",&s); + printf("\n"); + switch(s){ + case 1: Add_student();break; + case 2: Entrytime();break; + case 3: Exittime();break; + case 4: Student_status();break; + case 5: Stu_info();break; + case 6: studenthistory();break; + case 7: studentlist();break; + case 8: { + printf(" Enter the student roll number: "); + scanf("%s",c); + p = check(c); + if (p==0) printf(" student not registered\n"); + else if (p==1) printf(" student is registered\n");break; + } + case 9: warnings();break; + case 10: display(); + case 0: break; + default:break; + } + } +return 0; +} diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..170322a --- /dev/null +++ b/readme.txt @@ -0,0 +1,16 @@ +MY GATE IMPLEMENTATION in C + +Project Members: +Sai Abhijith Polineni (IMT2019519) +Pranjal Walia (IMT2019062) +Jayanth A (IMT2019038) +Shaik Muhammad Sameer (IMT2019522) +G Revanth Reddy (IMT2019517) +Ghazi Shazan Ahmed (IMT2019033) + +Project Running Instructions: +Enter the following commands in the terminal + make clean (only if .o files exist previously otherwise go forward) + make + ./main + diff --git a/stu_info.c b/stu_info.c new file mode 100644 index 0000000..f2c7067 --- /dev/null +++ b/stu_info.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include +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); +} diff --git a/stu_info.h b/stu_info.h new file mode 100644 index 0000000..684710c --- /dev/null +++ b/stu_info.h @@ -0,0 +1 @@ +void Stu_info(void); diff --git a/warnings.c b/warnings.c new file mode 100644 index 0000000..acf301e --- /dev/null +++ b/warnings.c @@ -0,0 +1,45 @@ +#include +#include +#include +struct myst4{ +char id[15]; +}st1; + //to display warnings to the ones who skipped an entry or exit + +struct myst1{ +char id[15]; +char name[15]; +}st2; + +void warnings(void){ + FILE *p1,*p2; + char c[15]; + char b[15]; + printf(" Enter the student ID number: "); + scanf("%s",c); + int count=0; + p2 = fopen("student","rb+"); + while(fread(&st2,sizeof(struct myst1),1,p2)){ + if (strcmp(c,st2.id)==0){ + strcpy(b,st2.name); + break; + }} + p1 = fopen("warnings","ab+"); + while(fread(&st1,sizeof(struct myst4),1,p1)) + { + if(strcmp(st1.id,c)==0) + { + count++; + } + } + if (count==0) + { + printf(" %s has no warnings\n",b); + } + else + { + printf(" %s has %d warnings\n",b,count); + } +} + + diff --git a/warnings.h b/warnings.h new file mode 100644 index 0000000..c9063a1 --- /dev/null +++ b/warnings.h @@ -0,0 +1 @@ +void warnings(void);