Advertisement
Sheyshya

Final Library management system

May 14th, 2019
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 44.07 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<windows.h>
  6.  
  7.  
  8. // profile structure
  9. struct profile {
  10.     char name[100];
  11.     char firstname[40];
  12.     char lastname[40];
  13.     char address[40];
  14.     long long int phoneNumber;
  15.     int userID ;
  16.  
  17. };
  18. //books structure
  19. struct books
  20. {   int userid;
  21.     int issuemonth;
  22.     int day,month,year;
  23.     int issueday;
  24.     int issueyear;
  25.     int submitmonth;
  26.     int submitday;
  27.     int submityear;
  28.     long long int isbn;
  29.     char user[50];
  30.     char bookname[50];
  31.     int quantity;
  32.     char category[30];
  33.     char author[40];
  34. };
  35. int userid1;
  36. long long int isbn1;
  37.  
  38. //Profjile Functions List
  39. void mainMenu();
  40. void adduser();
  41. void deluser();
  42. void edituser();
  43. void listuser();
  44. void searchuser();
  45. void adminlogin();
  46.  
  47. //book functions list
  48. void booksection();
  49. void addbook();
  50. void listbook();
  51. void searchbook();
  52. void delbook();
  53. void editbook();
  54. void viewissuedbook();
  55. void issuemain();
  56. void borrowbook();
  57. void returnbook();
  58. void category();
  59. void searchissue();
  60. void delissuebook();
  61. int viewissuedbookofuser(int);
  62. //main function.
  63. int main()
  64. {
  65.     system("color f");  //sets system color to bright white.
  66.   adminlogin();
  67.    return 0;
  68. }
  69.  
  70. void adminlogin()   //sets up admin login window.
  71. {
  72.     int i=0;
  73.     char aa[20],ch;
  74.     char password[30];
  75.     char username[30];
  76.     start:
  77.         printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n");
  78.    printf("\t\t\t..............................................\n\n");
  79.     printf("\t\t\t\t\t[ADMIN LOGIN]                \n\n");
  80.     printf("\t\t\tEnter your username: ");
  81.     scanf("%s",username);
  82.      printf("\t\t\tEnter your password: ");
  83.     while(ch!=13)
  84.    {
  85.  ch=_getch();
  86.  
  87.  if(ch!=13){
  88.  putch('*');
  89.  password[i] = ch;
  90.  i++;
  91.  }
  92.    }
  93.    password[i] = '\0';
  94.  
  95.  
  96.     if(strcmp(username,"a")==0){
  97.  
  98.    if(strcmp(password,"b")==0)
  99.    {
  100.        printf("\n\n");
  101.        char loading[]="\t\t\t\tloading.....................................!!\n";
  102.         while(loading[i]!='\0')
  103.     {
  104.         Sleep(15);
  105.         printf("%c",loading[i]);
  106.         i++;
  107.     }
  108.  
  109.         printf("\n                                      Login Success!!\n\n");
  110.         printf("\n                                Enter any key to continue! \n\n");
  111.         _getch();
  112.         mainMenu();
  113.     }
  114.    else{
  115.         printf("\n\n");
  116.        printf("\t\t\t..............................................\n");
  117.  
  118.     printf("\n                                      Wrong Password!!\n\n");
  119.     remsk:
  120.         printf("\n");
  121.     printf("\t\t\tWould you like to try again?[yes?/no?]: ");
  122.     scanf("%s",aa);
  123.  
  124.     if (strcmp(aa,"yes")==0)
  125.      {
  126.         system("cls");   //clears the screen before proceeding to the next step.
  127.       adminlogin();
  128.  
  129. }
  130.         if (strcmp(aa,"no")==0)
  131.         {
  132.            exit(0);
  133.         }
  134.         else if(1)
  135.         {
  136.             system("cls");
  137.             printf("\n");
  138.             printf("\t\t\tInvalid choice. Enter [yes/no] only!");
  139.             goto remsk;
  140.         }
  141.  
  142. }
  143.     }else{
  144.         printf("\n\n");
  145.        printf("\t\t\t..............................................\n");
  146.     printf("\n                                     User doesn't exist!\n\n\n\n");
  147.    goto remsk;
  148. }
  149.  
  150. _getch();
  151. mainMenu();
  152. }
  153.  
  154. //For Main Menu
  155. void mainMenu(){
  156.     system("color E");//yellow
  157.     system("cls");
  158.      printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  159.    printf("\t\t\t...........................................\n");
  160.     printf("\t\t\t:\t\t[MAIN MENU]\t          :\n");
  161.     printf("\t\t\t:.........................................:\n");
  162.     printf("\n\n\n\t\t\t1.Register user\n\t\t\t2.List users\n\t\t\t3.Edit user\n\t\t\t4.Delete User\n\t\t\t5.Search user\n\t\t\t6.Book section\n\t\t\t7.Exit\n");
  163.     printf("\t\t\tPress (1-7)\n");
  164.     printf("                       ..............................................\n");
  165.     switch(_getch()){
  166.         case '1': adduser();
  167.                   break;
  168.         case '2': listuser();
  169.                   break;
  170.         case '3': edituser();
  171.                   break;
  172.         case '4': deluser();
  173.                   break;
  174.         case '5': searchuser();
  175.                   break;
  176.         case '6': booksection();
  177.                   break;
  178.         case '7': exit(0);
  179.                   break;
  180.         default:
  181.  
  182.             printf("\nEnter any key to try again.");
  183.             _getch();
  184. system("cls");
  185.     mainMenu();
  186.  
  187.     }
  188. }
  189.  
  190. // For Adding New users
  191. void adduser(){
  192.  
  193.  
  194.  
  195.     struct profile b;
  196.     struct profile g;
  197.      int i,j;
  198.      int o;
  199.      int userID;
  200.     FILE *f;
  201.     FILE *another;
  202.     f=fopen("frecord.txt","ab");
  203.     f=fopen("frecord.txt","rb");
  204.  
  205.     system("cls");
  206.       printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  207.     printf("\t\t\t...........................................\n");
  208.     printf("\t\t\t:\t\t[USER REGISTER]\t          :\n");
  209.      printf("\t\t\t...........................................\n");
  210.  
  211.  printf("\t\t\t\tEnter first and last name: ");
  212.     scanf("%s %s",b.firstname,b.lastname);
  213.       fflush(stdin);
  214. name1:
  215. strcat(b.firstname," ");
  216.    strcat(b.firstname,b.lastname);
  217.    for (j=0;b.firstname[j]!='\0';++j)//copying
  218.       {
  219.    b.name[j]=b.firstname[j];
  220.       }
  221.       b.name[j]='\0';
  222.  
  223.    for (j=0;b.name[j]!='\0';++j)
  224.       {
  225.       if (b.name[j]>='0' && b.name[j]<='9')
  226.       {
  227.           printf("\n");
  228.           printf("\t\t\t\tInvalid name\n");
  229.            printf("\t\t\t\tEnter name again: ");
  230.     scanf("%s %s",b.firstname,b.lastname);
  231.       fflush(stdin);
  232.       goto name1;
  233.           break;
  234.       }
  235.       }
  236.  
  237.     printf("\t\t\t\tEnter address: ");
  238.     scanf("%s",&b.address);
  239.     fflush(stdin);
  240.     printf("\t\t\t\tEnter phone number: ");
  241.     scanf("%lld",&b.phoneNumber);
  242.     fflush(stdin);
  243.     chck:
  244.     if (b.phoneNumber<=9999999999 && b.phoneNumber>=99999999)
  245.     {
  246.  
  247.      printf("\t\t\t\tEnter UserID: ");
  248.  
  249.     while(scanf("%d", &userID)==0) //if scanf failed to scan an integer
  250. {
  251.     printf("Invalid input. Try again\n");
  252.     int c;
  253.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  254. }
  255.     fwrite(&b, sizeof(b), 1, f);
  256.  
  257.      another=fopen("frecord.txt","ab");
  258.      strcpy(g.name,b.name);
  259.         strcpy(g.address,b.address);
  260.         g.phoneNumber=b.phoneNumber;
  261.     while (fread(&b,sizeof(b),1,f)==1)
  262.     {
  263.         if (userID==b.userID)
  264.         {
  265.             fclose(f);
  266.             o=1;
  267.         }
  268.     }
  269.     if (o!=1)
  270.     {
  271.  
  272.         g.userID=userID;
  273.  
  274.         fwrite(&g, sizeof(g), 1, another);
  275.         printf("\t\t\tThe user id is available\n");
  276.         fclose(another);
  277.     }
  278.     else if (o==1){
  279.         printf("\t\t\tThe user ID already exists!!\n");
  280.         _getch();
  281.         mainMenu();
  282.     }
  283.  
  284.     }
  285.  
  286.  
  287.     else
  288.     {
  289.         printf("\n\t\t\t\tInvalid phone number!\n");
  290.         printf("\t\t\t\tEnter new phone number: ");
  291.     scanf("%lld",&b.phoneNumber);
  292.     fflush(stdin);
  293.     goto chck;
  294.     }
  295.  
  296.          printf("                        ............................................\n");
  297.  
  298.  
  299.  
  300.       printf("\nRecord Saved!\n");
  301.  
  302.           printf("\n\n");
  303.       printf("Would you like to add more user? [y/n]: ");
  304.             readd:
  305.       i=_getch();
  306.       if (i=='y')
  307.             {
  308.           adduser();
  309.                 }
  310.         if (i=='n')
  311.             {
  312.      printf("\nEnter any key to go back!");
  313.     _getch();
  314.     system("cls");
  315.     mainMenu();
  316.                 }
  317.                 else if(1)
  318.                 {
  319.                   goto readd;
  320.                 }
  321.  
  322. }
  323.  
  324. //Listing users profile
  325. void listuser(){
  326.  
  327.  
  328.     struct profile g;
  329.  
  330.     FILE *another;
  331.     another=fopen("frecord.txt","rb"); //binary read mode
  332.     system("cls");
  333.     if (another==NULL){
  334.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  335.         getch();
  336.         mainMenu();
  337.     }
  338.       printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  339.     printf("\t\t\t..................................................\n");
  340.     printf("\t\t\t:\t\t[LIST USERS PROFILE]             :\n");
  341.     printf("\t\t\t:................................................:\n");
  342.  
  343.     while(fread(&g,sizeof(g),1,another)==1){
  344.     printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",g.name,g.address,g.phoneNumber,g.userID);
  345.     }
  346. printf("............................................\n");
  347.     fclose(another);
  348.  
  349.     printf("\nEnter any key to go back!");
  350.     _getch();
  351.     system("cls");
  352.     mainMenu();
  353. }
  354.  
  355. //Editing profile
  356. void edituser(){
  357.     int id;
  358.     int found;
  359.    int e,j;
  360.  
  361.  
  362.  
  363.     struct profile b;
  364.  
  365.     FILE *fp;
  366.     FILE *ftemp;
  367.     fp = fopen("frecord.txt","rb");
  368.     ftemp = fopen("ftemprecord.txt","wb");
  369.     system("cls");
  370.   printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  371.    printf("\t\t\t..................................................\n");
  372.     printf("\t\t\t:\t\t[EDIT USERS PROFILE]             :\n");
  373.     printf("\t\t\t:................................................:\n");
  374.  
  375.     printf("\t\t\tEnter Users ID to modify: ");
  376.     scanf("%d",&id);
  377.     fflush(stdin);
  378.   printf("\n");
  379.     while(fread(&b,sizeof(b),1,fp)==1){
  380.             if(id!=b.userID)
  381.                 fwrite(&b,sizeof(b),1,ftemp);
  382.             if(id==b.userID){
  383.                 found = 1;
  384.             }
  385.     }
  386.     if (found == 1){
  387.   printf("\t\t\t\tEnter first and last name: ");
  388.     scanf("%s %s",b.firstname,b.lastname);
  389.       fflush(stdin);
  390. name1:
  391. strcat(b.firstname," ");
  392.    strcat(b.firstname,b.lastname);
  393.    for (j=0;b.firstname[j]!='\0';++j)
  394.       {
  395.    b.name[j]=b.firstname[j];
  396.       }
  397.       b.name[j]='\0';
  398.  
  399.    for (j=0;b.name[j]!='\0';++j)
  400.       {
  401.       if (b.name[j]>='0' && b.name[j]<='9')
  402.       {
  403.           printf("\n");
  404.           printf("\t\t\t\tInvalid name\n");
  405.            printf("\t\t\t\tEnter name again: ");
  406.     scanf("%s %s",b.firstname,b.lastname);
  407.       fflush(stdin);
  408.       goto name1;
  409.           break;
  410.       }
  411.       }
  412.     printf("\t\t\t\tEnter address: ");
  413.     scanf("%s",&b.address);
  414.     fflush(stdin);
  415.     printf("\t\t\t\tEnter phone number: ");
  416.     scanf("%lld",&b.phoneNumber);
  417.     fflush(stdin);
  418.     chck:
  419.     if (b.phoneNumber<=9999999999 && b.phoneNumber>=9999999)
  420.     {
  421.      printf("\t\t\t\tEnter UserID: ");
  422.  
  423.      while(scanf("%d", &b.userID)==0) //if scanf failed to scan an integer
  424. {
  425.     printf("\t\t\t\tInvalid input. Try again\n");
  426.     int c;
  427.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  428. }
  429.     }
  430.     else
  431.     {
  432.         printf("\n\t\t\t\tInvalid phone number!\n");
  433.         printf("\t\t\t\tEnter new phone number: ");
  434.     scanf("%lld",&b.phoneNumber);
  435.     fflush(stdin);
  436.     goto chck;
  437.     }
  438.         fwrite(&b,sizeof(b),1,ftemp);
  439.     }else if(found!=1){
  440.         printf("The contact does not exist!");
  441.     }
  442.  
  443.  
  444.  
  445.     fclose(fp);
  446.     fclose(ftemp);
  447.     remove("frecord.txt");
  448.     rename("ftemprecord.txt","frecord.txt");
  449.  
  450.     printf("\n\nEnter any key to go back!");
  451.     _getch();
  452.     system("cls");
  453.  
  454.     mainMenu();
  455.  
  456. }
  457.  
  458. //Searching profile
  459. void searchuser(){
  460.     int id;
  461.     int de,c;
  462.     struct profile b;
  463.  
  464.     FILE *fp;
  465.     fp=fopen("frecord.txt","rb");
  466.  
  467.     system("cls");
  468.  
  469.       printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  470.     printf("\t\t\t...........................................\n");
  471.     printf("\t\t\t:\t\t[SEARCH USER]\t          :\n");
  472.     printf("\t\t\t:.........................................:\n\n");
  473.     printf("\t\t\tEnter Users ID to search: ");
  474.     scanf("%d",&id);
  475.     printf("\n\n");
  476.     fflush(stdin);
  477. printf("\n");
  478.     while (fread(&b,sizeof(b),1,fp)==1)
  479.     {
  480.         if (id==b.userID){
  481.  
  482.         printf("\n[%s Profile ID]\n",b.name);
  483.     printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",b.name,b.address,b.phoneNumber,b.userID);
  484.     de=1;
  485. }
  486.     }
  487. if (de==1)
  488. {
  489.  
  490.     printf("\n\n");
  491.     printf("Would you like to search another user?[y/n]: ");
  492.      research:
  493.     c=_getch();
  494.     if (c=='y')
  495.     {
  496.         searchuser();
  497.             }
  498.             if (c=='n')
  499.             {
  500.                 printf("\n\n");
  501.               printf("\n\nEnter any key to go back!");
  502.  
  503.     _getch();
  504.     system("cls");
  505.     mainMenu();
  506.             }
  507.  
  508. }
  509.  
  510. if (de!=1)
  511. {
  512.     printf("\t\t\t\t\t*INVALID USER*");
  513.     printf("\n\nEnter any key to go back!");
  514.  
  515.     _getch();
  516.     system("cls");
  517.     mainMenu();
  518.  
  519. }
  520. fclose(fp);
  521. }
  522.  
  523.  
  524.  
  525.  
  526. //Deleting profile
  527. void deluser(){
  528.     char name[20];
  529.     int recordExists,id;
  530.  
  531.     system("cls");
  532.     fflush(stdin);
  533.  
  534.     struct profile b;
  535.  
  536.     FILE *fp;
  537.     FILE *ftemp;
  538.  
  539.     fp = fopen("frecord.txt","rb");
  540.  
  541.     ftemp = fopen("ftemprecord.txt","wb");
  542.   printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  543.     printf("\t\t\t...........................................\n");
  544.     printf("\t\t\t:\t\t[DELETE USER]\t          :\n");
  545.     printf("\t\t\t:.........................................:\n\n");
  546.     printf("\t\t\tEnter Users ID to delete: ");
  547.     scanf("%d",&id);
  548.     fflush(stdin);
  549.     printf("\n");
  550.  
  551.     while (fread( &b, sizeof(b), 1, fp) == 1) {
  552.         if (id!=b.userID)
  553.  
  554.           fwrite(&b, sizeof(b), 1, ftemp);
  555.         if (id==b.userID)
  556.           recordExists = 1;
  557.     }
  558.  
  559.     fclose(fp);
  560.     fclose(ftemp);
  561.  
  562.     if(recordExists!=1){
  563.         printf("The contact does not exist!");
  564.     }else{
  565.         remove("frecord.txt");
  566.         rename("ftemprecord.txt", "frecord.txt");
  567.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  568.     }
  569.  
  570.     printf("\n\nEnter any key to go back!");
  571.     _getch();
  572.     system("cls");
  573.  
  574.     mainMenu();
  575. }
  576.  
  577. void booksection()
  578. {
  579.      system("cls");
  580.      system("color A");
  581.        printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  582.     printf("\t\t\t.............................................\n");
  583.     printf("\t\t\t:\t\t[BOOK SECTION]\t            :\n");
  584.     printf("\t\t\t:...........................................:\n\n");
  585.     printf("\t\t\t1.Add book\n\t\t\t2.List Book\n\t\t\t3.Edit book\n\t\t\t4.Delete Book\n\t\t\t5.Search Book\n\t\t\t6.Issue Book\n\t\t\t7.Exit\n\t\t\t8.Go back\n");
  586.     printf("\t\t\tPress (1-8)\n");
  587.     printf("                       ..............................................\n");
  588.  
  589.     switch(_getch()){
  590.         case '1': addbook();
  591.                   break;
  592.  
  593.         case '2':listbook();
  594.                   break;
  595.  
  596.         case '3':editbook();
  597.                   break;
  598.  
  599.         case '4':delbook();
  600.                   break;
  601.  
  602.         case '5':searchbook();
  603.                   break;
  604.  
  605.         case '6':issuemain();
  606.                   break;
  607.  
  608.         case '7':exit(0);
  609.                   break;
  610.  
  611.         case '8': mainMenu();
  612.                  break;
  613.         default:
  614.  
  615.             printf("\nEnter any key to try again.");
  616.             _getch();
  617. system("cls");
  618. booksection();
  619. }
  620. }
  621. //add books in the library
  622. void addbook()
  623. {
  624.  
  625.  
  626.  
  627.     char m[20];
  628.  
  629. struct books d;
  630.  
  631.     FILE *fb;
  632.     fb=fopen("booksection.txt","ab");
  633.     char bookname[50];
  634. int s;
  635.     system("cls");
  636.     printf("\t\t\t...........................................\n");
  637.     printf("\t\t\t:\t\t[ADD BOOKS]\t          :\n");
  638.     printf("\t\t\t:.........................................:\n\n");
  639.     printf("\t\t\t\t[SELECT CATEGORY]\n\n");
  640.  
  641. printf("\t\t 1. Computer\n");
  642.  
  643. printf("\t\t 2. Science\n");
  644.  
  645. printf("\t\t 3. Medical\n");
  646.  
  647. printf("\t\t 4. Language\n");
  648.  
  649. printf("\t\t 5. Arts and literature\n");
  650.  
  651. printf("\t\t 6. History\n");
  652.  
  653. printf("\t\t 7. Back \n");
  654. printf("\t\tEnter your choice: ");
  655.     scanf("%d",&s);
  656.     fflush(stdin);
  657.  
  658.  
  659.  
  660. switch(s)
  661. {
  662.     case 1: strcpy(d.category,"Computer");
  663.     goto add;
  664.     break;
  665.  
  666.     case 2:strcpy(d.category,"Science");
  667.     goto add;
  668.     break;
  669.  
  670.        case 3:strcpy(d.category,"Medical");
  671.     goto add;
  672.     break;
  673.        case 4:strcpy(d.category,"Language");
  674.     goto add;
  675.     break;
  676.        case 5:strcpy(d.category,"Arts and literature");
  677.     goto add;
  678.     break;
  679.        case 6:strcpy(d.category,"History");
  680.     goto add;
  681.     break;
  682.        case 7:
  683.     booksection();
  684.     break;
  685.     default: printf("\t\tInvalid choice\n");
  686.       booksection();
  687.       break;
  688.  
  689. }
  690.  
  691.  
  692. add:
  693.  
  694. printf("\n\n");
  695.     printf("\t\t\tEnter the name of the book to be added: ");
  696. scanf("%s",d.bookname);
  697. fflush(stdin);
  698. printf("\t\t\tEnter the name of the author: ");
  699. scanf("%s",d.author);
  700. fflush(stdin);
  701.  
  702.     printf("\t\t\t\tEnter issue date(dd/mm/yy):\n ");
  703.     printf("\t\t\t\tEnter day: ");
  704.    scanf("%d",&d.day);
  705.    fflush(stdin);
  706.     dete:
  707.    if (d.day>0 && d.day<=30)
  708.     {
  709.          printf("\t\t\t\tEnter month: ");
  710.    scanf("%d",&d.month);
  711.     fflush(stdin);
  712.  
  713.     dete2:
  714.      if (d.month>0 && d.month<=12)
  715.          {
  716.     printf("\t\t\t\tEnter year: ");
  717.     scanf("%d",&d.year);
  718.    fflush(stdin);
  719.    dete3:
  720.      if (d.year>2018 && d.year<2020)
  721.      {
  722.          printf("\t\t\t\tEnter Book ISBN(5 digits):");
  723.          scanf("%lld",&d.isbn);
  724.          fflush(stdin);
  725.          dete4:
  726.         if (d.isbn>9999 && d.isbn<100000)
  727.         {
  728.           printf("\t\t\t\tEnter quantity of book:");
  729.          while(scanf("%d", &d.quantity)==0) //if scanf failed to scan an integer
  730. {
  731.     printf("\t\t\tInvalid input. Try again\n");
  732.     int c;
  733.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  734. }
  735.  
  736.         }
  737.         else{
  738.                 printf("\n");
  739.              printf("\t\t\t\tInvalid entry!!\n");
  740.     printf("\t\t\t\tEnter ISBN again: ");
  741.    scanf("%lld",&d.isbn);
  742.    fflush(stdin);
  743.           goto dete4;
  744.         }
  745.      }
  746.          else
  747.          {
  748.              printf("\n");
  749.              printf("\t\t\t\tInvalid entry!!\n");
  750.     printf("\t\t\t\tEnter year again: ");
  751.    scanf("%d",&d.year);
  752.    fflush(stdin);
  753.    goto dete3;
  754.  
  755.     }
  756.          }
  757.  
  758.    else
  759. {
  760.      printf("\n");
  761.        printf("\t\t\t\tInvalid entry!!\n");
  762.     printf("\t\t\t\tEnter month again: ");
  763.    scanf("%d",&d.month);
  764.    fflush(stdin);
  765.    goto dete2;
  766. }
  767.     }
  768.  
  769.     else{
  770.  printf("\n");
  771.        printf("\t\t\t\tInvalid entry!!\n");
  772.     printf("\t\t\t\tEnter day again: ");
  773.    scanf("%d",&d.day);
  774.    fflush(stdin);
  775.    goto dete;
  776.     }
  777.  
  778.  
  779.  
  780.     printf("                        ............................................\n");
  781.     fwrite(&d,sizeof(d),1,fb);
  782.     fclose(fb);
  783.  
  784.     printf("\n\t\t\tRecord Saved\n\n!");
  785.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  786.     scanf("%s",m);
  787.     if (strcmp(m,"main")==0)
  788.     {
  789.         system("cls");
  790.         mainMenu();
  791.     }
  792.     else if (1)
  793.     {
  794.     system("cls");
  795.    booksection();
  796.     }
  797. }
  798.  
  799. void listbook()
  800. {
  801.  struct books d;
  802.  
  803.     FILE *fb;
  804.  
  805.     fb=fopen("booksection.txt","rb"); //binary read mode
  806.     system("cls");
  807.     if (fb==NULL){
  808.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  809.         getch();
  810.         booksection();
  811.     }
  812.     printf("\t\t\t..................................................\n");
  813.     printf("\t\t\t:\t\t   [LIST BOOKS]                  :\n");
  814.     printf("\t\t\t:................................................:\n");
  815.  
  816.     while(fread(&d,sizeof(d),1,fb)==1){
  817.     printf("\nCategory: %s\nBook Name: %s\nAuthor: %s\nIssue date: %d/ %d/ %d\nBook ISBN: %lld\nBook Quantity: %d\n\n",d.category,d.bookname,d.author,d.day,d.month,d.year,d.isbn,d.quantity);
  818.     }
  819. printf("............................................\n");
  820.     fclose(fb);
  821.  
  822.     printf("\nEnter any key to go back!");
  823.     _getch();
  824.     system("cls");
  825.     booksection();
  826. }
  827. //edit book information
  828. void editbook(){
  829.     char m[20];
  830.     long long int bookid;
  831.     int bfound;
  832.    int be;
  833. int s;
  834.  
  835.  
  836.  
  837.  
  838.    struct books d;
  839.  
  840.     FILE *fb;
  841.     FILE *fbtemp;
  842.  
  843.     fb=fopen("booksection.txt","rb"); //binary read mode
  844.  
  845.     fbtemp = fopen("fbtemprecord.txt","wb");
  846.      system("cls");
  847.      printf("\t\t\t..................................................\n");
  848.     printf("\t\t\t:\t\t   [EDIT BOOKS]                  :\n");
  849.     printf("\t\t\t:................................................:\n");
  850.     printf("\t\t\tEnter BOOK ISBN to modify: ");
  851.     scanf("%lld",&bookid);
  852.     fflush(stdin);
  853.   printf("\n");
  854.     while(fread(&d,sizeof(d),1,fb)==1){
  855.             if(bookid!=d.isbn)
  856.                 fwrite(&d,sizeof(d),1,fbtemp);
  857.             if(bookid==d.isbn){
  858.                 bfound = 1;
  859.             }
  860.     }
  861.     if (bfound == 1){
  862.  
  863.      printf("\t\t\t\t[SELECT CATEGORY]\n\n");
  864.  
  865. printf("\t\t 1. Computer\n");
  866.  
  867. printf("\t\t 2. Science\n");
  868.  
  869. printf("\t\t 3. Medical\n");
  870.  
  871. printf("\t\t 4. Language\n");
  872.  
  873. printf("\t\t 5. Arts and literature\n");
  874.  
  875. printf("\t\t 6. History\n");
  876.  
  877. printf("\t\t 7. Back \n");
  878. printf("\t\tEnter your choice: ");
  879.     scanf("%d",&s);
  880.     fflush(stdin);
  881.  
  882.  
  883.  
  884. switch(s)
  885. {
  886.     case 1: strcpy(d.category,"Computer");
  887.     goto add;
  888.     break;
  889.  
  890.     case 2:strcpy(d.category,"Science");
  891.     goto add;
  892.     break;
  893.  
  894.        case 3:strcpy(d.category,"Medical");
  895.     goto add;
  896.     break;
  897.        case 4:strcpy(d.category,"Language");
  898.     goto add;
  899.     break;
  900.        case 5:strcpy(d.category,"Arts and literature");
  901.     goto add;
  902.     break;
  903.        case 6:strcpy(d.category,"History");
  904.     goto add;
  905.     break;
  906.        case 7:
  907.     booksection();
  908.     break;
  909.     default: printf("\t\tInvalid choice\n");
  910.       booksection();
  911.       break;
  912.  
  913. }
  914.  
  915.  
  916. add:
  917.  
  918.  
  919.  
  920.     printf("\t\t\tEnter the name of the book to be added: ");
  921.     scanf("%s",d.bookname);
  922.     fflush(stdin);
  923.     printf("\t\t\tEnter the name of the author: ");
  924. scanf("%s",d.author);
  925. fflush(stdin);
  926.  printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
  927.     printf("\t\t\t\tEnter day: ");
  928.    scanf("%d",&d.day);
  929.    fflush(stdin);
  930.     dete:
  931.    if (d.day>0 && d.day<=30)
  932.     {
  933.          printf("\t\t\t\tEnter month: ");
  934.    scanf("%d",&d.month);
  935.     fflush(stdin);
  936.  
  937.     dete2:
  938.      if (d.month>0 && d.month<=12)
  939.          {
  940.     printf("\t\t\t\tEnter year: ");
  941.     scanf("%d",&d.year);
  942.    fflush(stdin);
  943.    dete3:
  944.      if (d.year>2018 && d.day<2020)
  945.      {
  946.          printf("\t\t\t\tEnter Book ISBN(5 digits):");
  947.          scanf("%lld",&d.isbn);
  948.          fflush(stdin);
  949.          dete4:
  950.         if (d.isbn>9999 && d.isbn<100000)
  951.         {
  952.           printf("\t\t\t\tEnter quantity of book:");
  953.         while(scanf("%d", &d.quantity)==0) //if scanf failed to scan an integer
  954. {
  955.     printf("\t\t\t\tInvalid input. Try again\n");
  956.     int c;
  957.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  958. }
  959.         }
  960.         else{
  961.                 printf("\n");
  962.              printf("\t\t\t\tInvalid entry!!\n");
  963.     printf("\t\t\t\tEnter ISBN again: ");
  964.    scanf("%lld",&d.isbn);
  965.    fflush(stdin);
  966.           goto dete4;
  967.         }
  968.      }
  969.          else
  970.          {
  971.              printf("\n");
  972.              printf("\t\t\t\tInvalid entry!!\n");
  973.     printf("\t\t\t\tEnter year again: ");
  974.    scanf("%d",&d.year);
  975.    fflush(stdin);
  976.    goto dete3;
  977.  
  978.     }
  979.          }
  980.  
  981.    else
  982. {
  983.      printf("\n");
  984.        printf("\t\t\t\tInvalid entry!!\n");
  985.     printf("\t\t\t\tEnter month again: ");
  986.    scanf("%d",&d.month);
  987.    fflush(stdin);
  988.    goto dete2;
  989. }
  990.     }
  991.  
  992.     else{
  993.  printf("\n");
  994.        printf("\t\t\t\tInvalid entry!!\n");
  995.     printf("\t\t\t\tEnter day again: ");
  996.    scanf("%d",&d.day);
  997.    fflush(stdin);
  998.    goto dete;
  999.     }
  1000.  
  1001.  
  1002.         fwrite(&d,sizeof(d),1,fbtemp);
  1003.     }else if(bfound!=1){
  1004.         printf("\t\t\tThe book ID does not exist!");
  1005.     }
  1006.  
  1007.  
  1008.  
  1009.     fclose(fb);
  1010.     fclose(fbtemp);
  1011.     remove("booksection.txt");
  1012.     rename("fbtemprecord.txt","booksection.txt");
  1013. printf("\n\n");
  1014.    printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1015.     scanf("%s",m);
  1016.     if (strcmp(m,"main")==0)
  1017.     {
  1018.         system("cls");
  1019.         mainMenu();
  1020.     }
  1021.     else if (1)
  1022.     {
  1023.     system("cls");
  1024.    booksection();
  1025.     }
  1026. }
  1027.  
  1028.  
  1029.  
  1030. void searchbook(){
  1031.     char m[20];
  1032.     long long int bid;
  1033.     int bde,bc;
  1034.     struct books d;
  1035. int s;
  1036.     FILE *fb;
  1037.   fb=fopen("booksection.txt","rb");
  1038.  
  1039.     system("cls");
  1040.  
  1041.      printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1042.     printf("\t\t\t...........................................\n");
  1043.     printf("\t\t\t:\t\t[SEARCH BOOK]\t          :\n");
  1044.     printf("\t\t\t:.........................................:\n\n");
  1045.     printf("\t\t\tSearch by category or ISBN?\n");
  1046.     printf("\n\t\t\t1.Category\n\t\t\t2.ISBN\n");
  1047.     printf("\t\t\tEnter you choice: ");
  1048.     scanf("%d",&s);
  1049.  
  1050.       switch(s)
  1051.       {
  1052.           case 1: category();
  1053.           break;
  1054.  
  1055.           case 2:goto srch;
  1056.           break;
  1057.           default:printf("\t\t\tInvalid choice!!");
  1058.           _getch();
  1059.               booksection();
  1060.           break;
  1061.       }
  1062.  
  1063.     srch:
  1064.           system("cls");
  1065.     printf("\t\t\tEnter BOOK ID to search: ");
  1066.     scanf("%lld",&bid);
  1067.     printf("\n\n");
  1068.     fflush(stdin);
  1069. printf("\n");
  1070.     while (fread(&d,sizeof(d),1,fb)==1)
  1071.     {
  1072.         if (bid==d.isbn){
  1073.  
  1074.         printf("\n\t\t\t[%s Book Info]\n",d.bookname);
  1075.   printf("\n\t\t\tBook Name: %s\n\t\t\tAuthor: %s\n\t\t\tDate(dd/mm/yy): %d/ %d/ %d\n\t\t\tBook ISBN: %lld\n\t\t\tBook Quantity: %d\n\n",d.bookname,d.author,d.day,d.month,d.year,d.isbn,d.quantity);
  1076.     bde=1;
  1077. }
  1078.     }
  1079. if (bde==1)
  1080. {
  1081.  
  1082.     printf("\n\n");
  1083.     printf("\t\t\tWould you like to search another book?[y/n]: ");
  1084.      research:
  1085.     bc=_getch();
  1086.     if (bc=='y')
  1087.     {
  1088.         searchbook();
  1089.             }
  1090.             if (bc=='n')
  1091.             {
  1092.                 printf("\n\n");
  1093.               printf("\n\nEnter any key to go back!");
  1094.  
  1095.     _getch();
  1096.     system("cls");
  1097.     booksection();
  1098.             }
  1099.             else if(1)
  1100.             {
  1101.                 goto research;
  1102.             }
  1103.  
  1104. }
  1105. if (bde!=1)
  1106. {
  1107.     printf("\t\t\t\t\t*INVALID BOOK ISBN*");
  1108.     printf("\n\n");
  1109.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1110.     scanf("%s",m);
  1111.     if (strcmp(m,"main")==0)
  1112.     {
  1113.         system("cls");
  1114.         mainMenu();
  1115.     }
  1116.     else if (1)
  1117.     {
  1118.     system("cls");
  1119.    booksection();
  1120.     }
  1121. }
  1122. fclose(fb);
  1123. }
  1124.  
  1125. void category()
  1126. {
  1127.  
  1128.  
  1129.     char m[20];
  1130.     char cat[30];
  1131.     long long int bid;
  1132.     int bde,bc;
  1133.     struct books d;
  1134. int s;
  1135.     FILE *fb;
  1136.   fb=fopen("booksection.txt","rb");
  1137.  
  1138.     system("cls");
  1139.       printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1140.     printf("\t\t\t...........................................\n");
  1141.     printf("\t\t\t:\t\t[SEARCH BOOK]\t          :\n");
  1142.     printf("\t\t\t:.........................................:\n\n");
  1143.  
  1144.       printf("\t\t\t\t[SELECT CATEGORY]\n\n");
  1145.  
  1146. printf("\t\t 1. Computer\n");
  1147.  
  1148. printf("\t\t 2. Science\n");
  1149.  
  1150. printf("\t\t 3. Medical\n");
  1151.  
  1152. printf("\t\t 4. Language\n");
  1153.  
  1154. printf("\t\t 5. Arts and literature\n");
  1155.  
  1156. printf("\t\t 6. History\n");
  1157.  
  1158. printf("\t\t 7. Back \n");
  1159.  
  1160.  
  1161.  
  1162.     printf("\t\tEnter category to search: ");
  1163.     scanf("%s",cat);
  1164.         fflush(stdin);
  1165.  
  1166. printf("\n");
  1167.     while (fread(&d,sizeof(d),1,fb)==1)
  1168.     {
  1169.         if (strcmp(cat,d.category)==0){
  1170.  
  1171.         printf("\n\t\t\t[%s Book Info]\n",d.bookname);
  1172.    printf("\n\t\t\tBook Name: %s\n\t\t\tAuthor: %s\n\t\t\tDate(dd/mm/yy): %d/ %d/ %d\n\t\t\tBook ISBN: %lld\n\t\t\tBook Quantity: %d\n\n",d.bookname,d.author,d.day,d.month,d.year,d.isbn,d.quantity);
  1173.     bde=1;
  1174. }
  1175.     }
  1176. if (bde==1)
  1177. {
  1178.  
  1179.     printf("\n\n");
  1180.     printf("\t\t\tWould you like to search another book?[y/n]: ");
  1181.      research:
  1182.     bc=_getch();
  1183.     if (bc=='y')
  1184.     {
  1185.         searchbook();
  1186.             }
  1187.             if (bc=='n')
  1188.             {
  1189.                 printf("\n\n");
  1190.               printf("\n\nEnter any key to go back!");
  1191.  
  1192.     _getch();
  1193.     system("cls");
  1194.     booksection();
  1195.             }
  1196.             else if(1)
  1197.             {
  1198.                 goto research;
  1199.             }
  1200.  
  1201. }
  1202. if (bde!=1)
  1203. {
  1204.     printf("\t\t\t\t\t*Book Not Found!!");
  1205.     printf("\n\n");
  1206.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1207.     scanf("%s",m);
  1208.     if (strcmp(m,"main")==0)
  1209.     {
  1210.         system("cls");
  1211.         mainMenu();
  1212.     }
  1213.     else if (1)
  1214.     {
  1215.     system("cls");
  1216.    booksection();
  1217.     }
  1218. }
  1219. fclose(fb);
  1220.  
  1221. }
  1222.  
  1223. void delbook(){
  1224.     char m[20];
  1225.     char bname[20];
  1226.     int brecordExists;
  1227.     long long int bid;
  1228.  
  1229.     system("cls");
  1230.     fflush(stdin);
  1231.  
  1232.     struct books d;
  1233.  
  1234.     FILE *fb;
  1235.     FILE *fbtemp;
  1236.  
  1237.    fb=fopen("booksection.txt","rb");
  1238.     fbtemp = fopen("fbtemprecord.txt","wb");
  1239.     printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1240.  
  1241.     printf("\t\t\t...........................................\n");
  1242.     printf("\t\t\t:\t\t[DELETE BOOK]\t          :\n");
  1243.     printf("\t\t\t:.........................................:\n\n");
  1244.     printf("\t\t\tEnter Book ISBN to delete: ");
  1245.     scanf("%lld",&bid);
  1246.     fflush(stdin);
  1247.     printf("\n");
  1248.  
  1249.     while (fread( &d, sizeof(d), 1, fb) == 1) {
  1250.         if (bid!=d.isbn)
  1251.           fwrite(&d, sizeof(d), 1, fbtemp);
  1252.         if (bid==d.isbn)
  1253.           brecordExists = 1;
  1254.     }
  1255.  
  1256.     fclose(fb);
  1257.     fclose(fbtemp);
  1258.  
  1259.     if(brecordExists!=1){
  1260.         printf("\t\t\tThe book does not exist!");
  1261.     }else{
  1262.         remove("booksection.txt");
  1263.         rename("fbtemprecord.txt", "booksection.txt");
  1264.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  1265.     }
  1266. printf("\n\n");
  1267.   printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1268.     scanf("%s",m);
  1269.     if (strcmp(m,"main")==0)
  1270.     {
  1271.         system("cls");
  1272.         mainMenu();
  1273.     }
  1274.     else if (1)
  1275.     {
  1276.     system("cls");
  1277.    booksection();
  1278.     }
  1279. }
  1280.  
  1281. void issuemain()
  1282. {
  1283.  system("color E");//yellow
  1284.     system("cls");
  1285.       printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1286.     printf("\t\t\t...........................................\n");
  1287.     printf("\t\t\t:\t\t[ISSUE BOOKS]\t          :\n");
  1288.     printf("\t\t\t:.........................................:\n");
  1289.     printf("\n\n\n\t\t\t1.Borrow book\n\t\t\t2.View Issued Books\n\t\t\t3.Search Book\n\t\t\t4.Return book\n\t\t\t5.Remove Issued Books\n\t\t\t6.Exit\n\t\t\t7.Go back\n");
  1290.     printf("\t\t\tPress (1-6)\n");
  1291.     printf("                       ..............................................\n");
  1292.     switch(_getch()){
  1293.         case '1': borrowbook();
  1294.         break;
  1295.  
  1296.         case '2':viewissuedbook();
  1297.         break;
  1298.  
  1299.         case '3':searchissue();
  1300.         break;
  1301.  
  1302.         case '4':returnbook();
  1303.         break;
  1304.  
  1305.         case '5':delissuebook();
  1306.         break;
  1307.  
  1308.         case '6': exit(0);
  1309.         break;
  1310.  
  1311.         case '7':booksection();
  1312.                 break;
  1313.  
  1314.         default:
  1315.  
  1316.             printf("\nEnter any key to try again.");
  1317.             _getch();
  1318. system("cls");
  1319.     mainMenu();
  1320.  
  1321.     }
  1322. }
  1323.  
  1324.  
  1325.  
  1326. void borrowbook()
  1327. {
  1328.  
  1329.  
  1330.     struct profile g;
  1331.     struct books e;
  1332.     struct books d;
  1333.     char borrow[20];
  1334.     int quantity,quantity1,n1;
  1335.     FILE *another,*fb;
  1336.     FILE *issue;
  1337.     int m,k,j,i,n;
  1338.     issue=fopen("issuebook.txt","ab");
  1339.     another=fopen("frecord.txt","rb");
  1340.     fb=fopen("booksection.txt","rb");
  1341.  
  1342.  
  1343.     system("cls");
  1344.         printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1345.     printf("\t\t\t...........................................\n");
  1346.     printf("\t\t\t:\t\t[BORROW BOOKS]\t          :\n");
  1347.     printf("\t\t\t:.........................................:\n");
  1348.     printf("\t\t\tEnter reader's ID: ");
  1349.  
  1350.     scanf("%d",&userid1);
  1351. fflush(stdin);
  1352.  
  1353.  
  1354. while(fread(&g,sizeof(g),1,another)==1)
  1355. {
  1356.     if (userid1==g.userID)
  1357.     {
  1358. e.userid=userid1;
  1359.  
  1360. m=1;
  1361.     }
  1362. }
  1363.  
  1364.  
  1365. if (m!=1)
  1366. {
  1367.    printf("\t\t\tNot found");
  1368.    _getch();
  1369.    issuemain();
  1370. }
  1371. else
  1372. {
  1373.  
  1374.        printf("\t\t\tHave you borrowed the book previously?: ");
  1375.        scanf("%s",borrow);
  1376.          fflush(stdin);
  1377.        if (strcmp(borrow,"yes")==0)
  1378.        {
  1379.            viewissuedbookofuser(userid1);
  1380.            printf("\t\t\tHow many books did you borrow?: ");
  1381.            while(scanf("%d", &n1)==0) //if scanf failed to scan an integer
  1382. {
  1383.     printf("Invalid input. Try again\n");
  1384.     int c;
  1385.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  1386. }
  1387.  
  1388.            if (n1>3)
  1389.            {
  1390.                printf("\t\t\tError! Cant borrow more than 3 books!!");
  1391.                _getch();
  1392.                issuemain();
  1393.            }
  1394.            else if (n1==0)
  1395.            {
  1396.             printf("\t\t\t0 books can't be borrowed!!\n");
  1397.            _getch();
  1398.            issuemain();
  1399.            }
  1400.            else
  1401.            {
  1402.  
  1403.  
  1404.            printf("\t\t\tEnter the number of books you want to borrow: ");
  1405.        while(scanf("%d", &quantity)==0) //if scanf failed to scan an integer
  1406. {
  1407.     printf("Invalid input. Try again\n");
  1408.     int c;
  1409.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  1410. }
  1411.  
  1412.        quantity1=quantity+n1;
  1413.        if (quantity==0)
  1414.        {
  1415.            printf("\t\t\t0 books can't be borrowed!!\n");
  1416.            _getch();
  1417.            issuemain();
  1418.        }
  1419.  
  1420.            }
  1421.  
  1422.        }
  1423.  
  1424.  
  1425.        else if (strcmp(borrow,"no")==0)
  1426.        {
  1427.        printf("\t\t\tEnter the number of books you want to borrow: ");
  1428.         while(scanf("%d", &quantity)==0) //if scanf failed to scan an integer
  1429. {
  1430.     printf("\t\t\t\tInvalid input. Try again\n");
  1431.     int c;
  1432.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  1433. }
  1434.        quantity1=quantity;
  1435.         if (quantity==0)
  1436.        {
  1437.            printf("\t\t\t0 books can't be borrowed!!\n");
  1438.            _getch();
  1439.            issuemain();
  1440.        }
  1441.  
  1442.  
  1443.  
  1444.        }
  1445.  
  1446.  else if (1)
  1447.        {
  1448.            printf("\t\t\tInvalid entry!\n");
  1449.            _getch();
  1450.            issuemain();
  1451.        }
  1452.  
  1453.        if (quantity1>0 && quantity1<4)
  1454.        {
  1455.            e.quantity=quantity;
  1456. start1:
  1457.            for (i=0;i<quantity;i++)
  1458.            {
  1459.  
  1460.                printf("\t\t\tEnter ISBN of the book(5 digits): ");
  1461.       scanf("%d", &isbn1); //if scanf failed to scan an integer
  1462.  
  1463.  
  1464.  
  1465.     while(fread(&d,sizeof(d),1,fb)==1)
  1466.    {
  1467.  
  1468.      if (isbn1==d.isbn)
  1469.      {
  1470.           e.isbn=isbn1;
  1471.  
  1472.          k=1;
  1473.  
  1474.      }
  1475.    }
  1476.  
  1477.    if (k!=1)
  1478.    {
  1479.        printf("\t\t\tBook ISBN not found!!");
  1480.        _getch();
  1481.        issuemain();
  1482.    }
  1483.  
  1484.  else if (k==1)
  1485.    {
  1486.  
  1487.   printf("\t\t\tHow many books of this ISBN do you want to borrow?: ");
  1488.   while(scanf("%d", &n)==0) //if scanf failed to scan an integer
  1489. {
  1490.     printf("\t\t\tInvalid input. Try again\n");
  1491.     int c;
  1492.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  1493. }
  1494.  
  1495. if (n>d.quantity)
  1496. {
  1497.     printf("\t\t\tInvalid entry!!\n");
  1498.     _getch();
  1499.     issuemain();
  1500. }
  1501. if (n==quantity)
  1502. {
  1503.     goto start;
  1504. }
  1505. if (n==1)
  1506. {
  1507.     quantity=quantity-1;
  1508.  goto start1;
  1509. }
  1510. else{
  1511.     printf("\t\t\tInvalid entry!!\n");
  1512. _getch();
  1513. issuemain();
  1514. }
  1515.    }
  1516.    }
  1517.        }
  1518.  
  1519.  
  1520.        else
  1521.        {
  1522.            printf("\t\t\tYou can't have more than three books!!\n");
  1523.            _getch();
  1524.            issuemain();
  1525.        }
  1526.  
  1527. start:
  1528.      printf("\t\t\tEnter the issue date:\n ");
  1529.     printf("\t\t\t\tEnter day: ");
  1530.    scanf("%d",&e.issueday);
  1531.     dete:
  1532.    if (e.issueday>0 && e.issueday<=30)
  1533.     {
  1534.          printf("\t\t\t\tEnter month: ");
  1535.    scanf("%d",&e.issuemonth);
  1536.     fflush(stdin);
  1537.  
  1538.     dete2:
  1539.      if (e.issuemonth>0 && e.issuemonth<=12)
  1540.          {
  1541.     printf("\t\t\t\tEnter year: ");
  1542.     scanf("%d",&e.issueyear);
  1543.    fflush(stdin);
  1544.    dete3:
  1545.      if (e.issueyear>2018 && e.issueyear <2020)
  1546.      {
  1547.          e.submitday=e.issueday;
  1548.           e.submitmonth=e.issuemonth+1;
  1549.           if (e.submitmonth>12)
  1550.           {
  1551.               e.submityear=e.issueyear+1;
  1552.               e.submitmonth=e.submitmonth-12;
  1553.           }
  1554.           else{
  1555.             e.submityear=e.issueyear;
  1556.           }
  1557.  
  1558.          printf("\t\t\t\tReturn date:%d/ %d/ %d ",e.submitday,e.submitmonth,e.submityear );
  1559.           fwrite(&e,sizeof(e),1,issue);
  1560.    fclose(issue);
  1561.          _getch();
  1562.          issuemain();
  1563.  
  1564.      }
  1565.  
  1566.          else
  1567.          {
  1568.              printf("\n");
  1569.              printf("\t\t\t\tInvalid entry!!\n");
  1570.     printf("\t\t\t\tEnter year again: ");
  1571.    scanf("%d",&e.issueyear);
  1572.    goto dete3;
  1573.  
  1574.     }
  1575.          }
  1576.  
  1577.    else
  1578. {
  1579.      printf("\n");
  1580.        printf("\t\t\t\tInvalid entry!!\n");
  1581.     printf("\t\t\t\tEnter month again: ");
  1582.    scanf("%d",&e.issuemonth);
  1583.    goto dete2;
  1584. }
  1585.     }
  1586.  
  1587.     else{
  1588.  printf("\n");
  1589.        printf("\t\t\t\tInvalid entry!!\n");
  1590.     printf("\t\t\t\tEnter day again: ");
  1591.    scanf("%d",&e.issueday);
  1592.    goto dete;
  1593.     }
  1594.  
  1595.  
  1596. }
  1597. fclose(fb);
  1598.  
  1599. fclose(another);
  1600.  
  1601.  
  1602. }
  1603. int viewissuedbookofuser(userid1)
  1604. {
  1605.      struct books e;
  1606.     FILE *issue;
  1607.  
  1608.     issue=fopen("issuebook.txt","rb");
  1609.  
  1610.     if (issue==NULL){
  1611.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1612.         getch();
  1613.         issuemain();
  1614.     }
  1615.  
  1616.  
  1617.     while(fread(&e,sizeof(e),1,issue)==1){
  1618.     printf("\n\t\t\tUser ID: %d\n\t\t\tBook Quantity: %d\n\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.userid,e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1619.  
  1620.     }
  1621.  
  1622.     fclose(issue);
  1623. return 0;
  1624.  
  1625. }
  1626.  
  1627.  
  1628.  
  1629. void viewissuedbook()
  1630. {
  1631.  
  1632.     struct books e;
  1633.     FILE *issue;
  1634.  
  1635.     issue=fopen("issuebook.txt","rb");
  1636.     system("cls");
  1637.     if (issue==NULL){
  1638.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1639.         getch();
  1640.         issuemain();
  1641.     }
  1642.       printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1643.     printf("\t\t\t..................................................\n");
  1644.     printf("\t\t\t:\t\t[LIST ISSUED BOOKS]             :\n");
  1645.     printf("\t\t\t:................................................:\n");
  1646.  
  1647.     while(fread(&e,sizeof(e),1,issue)==1){
  1648.     printf("\nUser ID: %d\nBook Quantity: %d\nIssue Date [dd/mm/yy]: %d/ %d/ %d\nReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.userid,e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1649.  
  1650.     }
  1651.  
  1652. printf("............................................\n");
  1653.     fclose(issue);
  1654.  
  1655.     printf("\nEnter any key to go back!");
  1656.     _getch();
  1657.     system("cls");
  1658.     issuemain();
  1659. }
  1660.  
  1661.  
  1662.  
  1663. void returnbook()
  1664. {
  1665.      struct books e;
  1666.     FILE *issue;
  1667.     int i,j;
  1668.     int quantity,quantity1;
  1669.     int day,month,year;
  1670.     int fine1;
  1671.    issue=fopen("issuebook.txt","rb");
  1672.     if (issue==NULL){
  1673.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1674.         getch();
  1675.         issuemain();
  1676.     }
  1677. system("cls");
  1678.   printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1679.      printf("\t\t\t..................................................\n");
  1680.     printf("\t\t\t:\t\t[RETURN BOOKS]             :\n");
  1681.     printf("\t\t\t:................................................:\n");
  1682.  
  1683.    printf("\t\t\tEnter USER ID: ");
  1684.    scanf("%d",&userid1);
  1685.    while(fread(&e,sizeof(e),1,issue)==1){
  1686.         if (userid1==e.userid)
  1687.         {
  1688.            i=1;
  1689.         }
  1690.  
  1691.     }
  1692.     if (i==1)
  1693.     {
  1694.         printf("\n\t\t\t\tBook Quantity: %d\n\t\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1695.         printf("\t\t\t\tEnter the quantity of book returned: ");
  1696.          while(scanf("%d", &quantity)==0) //if scanf failed to scan an integer
  1697. {
  1698.     printf("\t\t\t\tInvalid input. Try again\n");
  1699.     int c;
  1700.     while((c=getchar())!='\n' && c!=EOF); //clear the stdin
  1701. }
  1702.         if (quantity<e.quantity)
  1703.         {
  1704.             quantity1=e.quantity-quantity;
  1705.             printf("\t\t\t\t%d books not returned!!\n",quantity1);
  1706.  
  1707.             quantity=quantity1*200;
  1708.  
  1709.             goto start;
  1710.         }
  1711.         else if (quantity==e.quantity)
  1712.         {
  1713.            printf("\t\t\t\tAll the books are returned!!\n");
  1714.            quantity=0;
  1715.            goto start;
  1716.         }
  1717.         else if (quantity>e.quantity)
  1718.         {
  1719.             printf("\t\t\t\tInvalid quantity!!\n");
  1720.             _getch();
  1721.             issuemain();
  1722.         }
  1723.         start:
  1724.         printf("\t\t\t\tEnter the date on which the user returned the book:\n");
  1725.         printf("\t\t\t\tEnter day: ");
  1726.    scanf("%d",&day);
  1727.     dete:
  1728.    if (day>0 && day<=30)
  1729.     {
  1730.          printf("\t\t\t\tEnter month: ");
  1731.    scanf("%d",&month);
  1732.     fflush(stdin);
  1733.     if (e.submitmonth==12)
  1734.     {
  1735.         month=12+month;
  1736.         goto start1;
  1737.     }
  1738.  
  1739.     dete2:
  1740.      if (month>0 && month<=12)
  1741.          {
  1742.     printf("\t\t\t\tEnter year: ");
  1743.     scanf("%d",&year);
  1744.    fflush(stdin);
  1745.    dete3:
  1746.      if (year>2018 && day<2021)
  1747.      {
  1748.  
  1749.  
  1750.         if (((month==e.issuemonth)||(month==e.submitmonth))&&((year==e.issueyear)||(year==e.submityear)))
  1751.         {
  1752.             printf("\t\t\t\tBook is returned on time!!\n");
  1753.             _getch();
  1754.           issuemain();
  1755.         }
  1756.  
  1757.  start1:
  1758.  if ((month>e.submitmonth)||(year>e.submityear))
  1759. {
  1760.     j=day-e.submitday;
  1761.     year=year-e.submityear;
  1762.     day=365*year;
  1763.     month=month-e.submitmonth;
  1764.     day=day+30*month+j;
  1765.     fine1=2*day+quantity;
  1766.     printf("\t\t\t\tThe user has to pay Rs %d.",fine1);
  1767.     _getch();
  1768. issuemain();
  1769.  
  1770. }
  1771.  
  1772.      }
  1773.          else
  1774.          {
  1775.              printf("\n");
  1776.              printf("\t\t\t\tInvalid entry!!\n");
  1777.     printf("\t\t\t\tEnter year again: ");
  1778.    scanf("%d",&year);
  1779.    goto dete3;
  1780.  
  1781.     }
  1782.          }
  1783.  
  1784.    else
  1785. {
  1786.      printf("\n");
  1787.        printf("\t\t\t\tInvalid entry!!\n");
  1788.     printf("\t\t\t\tEnter month again: ");
  1789.    scanf("%d",&month);
  1790.    goto dete2;
  1791. }
  1792.     }
  1793.  
  1794.     else{
  1795.  printf("\n");
  1796.        printf("\t\t\t\tInvalid entry!!\n");
  1797.     printf("\t\t\t\tEnter day again: ");
  1798.    scanf("%d",&day);
  1799.    goto dete;
  1800.     }
  1801.  
  1802.  
  1803.     }
  1804.     else
  1805.     {
  1806.         printf("\t\t\tUser not found!\n");
  1807.         _getch();
  1808.         issuemain();
  1809.     }
  1810.  
  1811. fclose(issue);
  1812. }
  1813.  
  1814.  
  1815. void searchissue(){
  1816.     int id;
  1817.     int de,c;
  1818.  
  1819.    struct books e;
  1820.     FILE *issue;
  1821.     int i,j;
  1822.     int quantity,quantity1;
  1823.     int day,month,year;
  1824.     int fine1;
  1825.    issue=fopen("issuebook.txt","rb");
  1826.     if (issue==NULL){
  1827.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1828.         getch();
  1829.         issuemain();
  1830.     }
  1831.  
  1832.     system("cls");
  1833.  
  1834.   printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1835.     printf("\t\t\t...........................................\n");
  1836.     printf("\t\t\t:\t\t[SEARCH USER]\t          :\n");
  1837.     printf("\t\t\t:.........................................:\n\n");
  1838.     printf("\t\t\tEnter Users ID to search: ");
  1839.     scanf("%d",&id);
  1840.     printf("\n\n");
  1841.     fflush(stdin);
  1842. printf("\n");
  1843.     while (fread(&e,sizeof(e),1,issue)==1)
  1844.     {
  1845.         if (id==e.userid){
  1846.    printf("\n\t\t\t\tBook Quantity: %d\n\t\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1847.     de=1;
  1848. }
  1849.     }
  1850. if (de==1)
  1851. {
  1852.  
  1853.     printf("\n\n");
  1854.     printf("Would you like to search another user?[y/n]: ");
  1855.      research:
  1856.     c=_getch();
  1857.     if (c=='y')
  1858.     {
  1859.         searchuser();
  1860.             }
  1861.             if (c=='n')
  1862.             {
  1863.                 printf("\n\n");
  1864.               printf("\n\nEnter any key to go back!");
  1865.  
  1866.     _getch();
  1867.     system("cls");
  1868.     mainMenu();
  1869.             }
  1870.  
  1871. }
  1872.  
  1873. if (de!=1)
  1874. {
  1875.     printf("\t\t\t\t\t*INVALID USER*");
  1876.     printf("\n\nEnter any key to go back!");
  1877.  
  1878.     _getch();
  1879.     system("cls");
  1880.     mainMenu();
  1881.  
  1882. }
  1883. fclose(issue);
  1884. }
  1885.  
  1886.  
  1887. void delissuebook(){
  1888.     char m[20];
  1889.     char bname[20];
  1890.     int brecordExists;
  1891.     long long int bid;
  1892.  
  1893.     system("cls");
  1894.     fflush(stdin);
  1895.  
  1896.     struct books e;
  1897.  
  1898.     FILE *fb;
  1899.     FILE *fbtemp;
  1900.  
  1901.    fb=fopen("issuebook.txt","r");
  1902.     fbtemp = fopen("fbtempissue.txt","w");
  1903.      printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
  1904.     printf("\t\t\t...........................................\n");
  1905.     printf("\t\t\t:\t\t[DELETE BOOK]\t          :\n");
  1906.     printf("\t\t\t:.........................................:\n\n");
  1907.     printf("\t\t\tEnter UserID to delete: ");
  1908.     scanf("%lld",&bid);
  1909.     fflush(stdin);
  1910.     printf("\n");
  1911.  
  1912.     while (fread( &e, sizeof(e), 1, fb) == 1) {
  1913.         if (bid!=e.userid)
  1914.           fwrite(&e, sizeof(e), 1, fbtemp);
  1915.         if (bid==e.userid)
  1916.           brecordExists = 1;
  1917.     }
  1918.  
  1919.     fclose(fb);
  1920.     fclose(fbtemp);
  1921.  
  1922.     if(brecordExists!=1){
  1923.         printf("\t\t\tThe user does not exist!");
  1924.     }else{
  1925.         remove("issuebook.txt");
  1926.         rename("fbtempissue.txt", "issuebook.txt");
  1927.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  1928.     }
  1929. printf("\n\n");
  1930.   printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1931.     scanf("%s",m);
  1932.     if (strcmp(m,"main")==0)
  1933.     {
  1934.         system("cls");
  1935.         issuemain();
  1936.     }
  1937.     else if (1)
  1938.     {
  1939.     system("cls");
  1940.    issuemain();
  1941.     }
  1942. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement