Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Project C Language
- //Library System
- //CreateBy
- //1.Kriangkrai Aroontheerapoj Sec.3 ID:5488026
- //2.
- //3.
- //======================= Declaration ===================================//
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<time.h>
- void chkUsrOrStaff(int);
- void chkMember(int);
- void wantToDo(int);
- int registMember(char);
- int addBook(char);
- int removeBook(char);
- int OverDue(char);
- int borrowBook();
- int returnBook();
- struct usernamepassword
- {
- char username[8+1];
- char password[8+1];
- };
- struct book
- {
- char bookID[8+1];
- char bookName[500+1];
- };
- struct usernamepassword user[100];
- struct usernamepassword chkuser[1];
- struct book book[100];
- struct book chkbook[1];
- int i=0,count=0;
- FILE *fid;
- FILE *fie;
- //======================= Main Function ===================================//
- int main()
- {
- int usrOrStaff;
- printf("\n\n====== Welcome to Library System ======\n\n");
- printf("Who are You?\n");
- printf("1. User\n");
- printf("2. Staff\n\n");
- printf("Enter 1 or 2: ");
- scanf("%d",&usrOrStaff);
- system("cls");
- chkUsrOrStaff(usrOrStaff);
- getch();
- return 0;
- }
- //======================= check User Or Staff ===========================//
- void chkUsrOrStaff(int usrOrStaff)
- { int memOrNot;
- if(usrOrStaff==1)
- {
- printf("\n\nYou are User");
- printf("\n\n========================================\n\n");
- printf("Are you Member?\n");
- printf("1. Yes\n");
- printf("2. No\n\n");
- printf("Enter 1 or 2: ");
- scanf("%d",&memOrNot);
- system("cls");
- chkMember(memOrNot);
- }
- else if(usrOrStaff==2)
- {
- printf("You are Staff");
- }
- }
- //========================== check Member ==============================//
- void chkMember(int memOrNot)
- { int chkWant,chkUsr,chkPsw,chkRegis,count;
- struct usernamepassword regUser[1];
- if(memOrNot==1)
- {
- printf("\n\nYou are member");
- printf("\n\n====== Plese enter username and password ====== \n\n");
- fid = fopen("user.txt","r");
- if(!(fid==NULL))
- {
- while(!feof(fid))
- {
- fscanf(fid,"%s %s \n",user[i].username,user[i].password);
- i++;
- count++;
- }
- }
- do
- {
- printf("\nEnter username: ");
- scanf("%s",&chkuser[0].username);
- printf("Enter password: ");
- scanf("%s",&chkuser[0].password);
- for(i=0;i<count;i++)
- {
- chkUsr=strcmp(chkuser[0].username,user[i].username);
- chkPsw=strcmp(chkuser[0].password,user[i].password);
- if(chkUsr==0 && chkPsw==0)
- {
- break;
- }
- }
- }while(chkUsr!=0 || chkPsw!=0);
- fclose(fid);
- printf("Password Correct");
- system("cls");
- printf("\n\n========== Welcome ==========\n\n");
- printf("---- What do you want to do? ----\n");
- printf("1.Borrow Book(s)");
- printf("\n2.Return Book(s)");
- printf("\n\nEnter 1 or 2: ");
- scanf("%d",&chkWant);
- wantToDo(chkWant);
- }
- else if(memOrNot==2)
- {
- printf("You are non-member\n");
- printf("\n==========================\n");
- printf("What do you want to do\n\n");
- printf("1. Register\n");
- printf("2. Exit\n\n");
- printf("Enter 1 or 2: ");
- scanf("%d",&chkRegis);
- if(chkRegis==1)
- {
- system("cls");
- fid = fopen("user.txt","a+t");
- printf("======= Register System =======\n\n");
- printf("Enter username: ");
- scanf("%s",regUser[0].username);
- printf("Enter password: ");
- scanf("%s",regUser[0].password);
- fprintf(fid,"\n%s \t %s",regUser[0].username,regUser[0].password);
- printf("\nRegister Successful.");
- printf("\n\nNow you can login and borrow/return book(s).");
- fclose(fid);
- getch();
- system("cls");
- memOrNot=1;
- chkMember(memOrNot);
- }
- else if(chkRegis==2)
- {
- exit(1);
- }
- }
- }
- //========================== Check What User Want to do======================//
- void wantToDo(int chkWant)
- {
- if(chkWant==1)
- {
- borrowBook();
- }
- else if(chkWant==2)
- {
- }
- }
- //========================== Borrow Books system ============================//
- int borrowBook(int qty)
- {
- int qtyBorrow,chkBookID,j,chk;
- char borrowBookID[8];
- system("cls");
- printf("\n\n====== Borrow Book(s) System ======\n\n");
- do
- {
- printf("How many Book(s) that you want to Borrow(Maximum 5): ");
- scanf("%d",&qtyBorrow);
- }while(qtyBorrow>5);
- fie = fopen("book.txt","r");
- if(!(fie==NULL))
- {
- while(!feof(fie))
- {
- fscanf(fie,"%s\n",book[i].bookID);
- fgets(book[i].bookName,51,fie);
- i++;
- count++;
- }
- }
- for(i=0;i<count;i++)
- {
- printf("%s\t%s",book[i].bookID,book[i].bookName);
- }
- for(i=0;i<qtyBorrow;i++)
- {
- printf("\n\nEnter %d book ID: ",i+1);
- scanf("%s",&borrowBookID[i]);
- }
- printf("\nYou borrow:\n");
- for(i=0;i<qtyBorrow;i++)
- { for(j=0;j<count;j++)
- {
- if(strcmp(&borrowBookID[i],book[j].bookID)==0)
- {
- chk=j;
- break;
- }
- }
- printf("%s\t%s",book[chk].bookID,book[chk].bookName);
- }
- }
Add Comment
Please, Sign In to add comment