Advertisement
Sheyshya

library management system 2

Mar 9th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.88 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. {
  21.     char yourname[40];
  22.     char bookname[40];
  23.     int issuemonth;
  24.     long long int day,month,year;
  25.     int issueday;
  26.     int issueyear;
  27.     int bookID;
  28.     int submitmonth;
  29.     int submitday;
  30.     int submityear;
  31. };
  32.  
  33. //Functions List
  34. void mainMenu();
  35. void adduser();
  36. void deluser();
  37. void edituser();
  38. void listuser();
  39. void searchuser();
  40. void adminlogin();
  41.  
  42. void booksection();
  43. void addbook();
  44. void listbook();
  45. void searchbook();
  46. void delbook();
  47. void editbook();
  48. void issuebook();
  49.  
  50. //main function.
  51. int main()
  52. {
  53.     system("color f");  //sets system color to bright white.
  54.   adminlogin();
  55.    return 0;
  56. }
  57.  
  58. void adminlogin()   //sets up admin login window.
  59. {
  60.     int i=0;
  61.     char aa[20],ch;
  62.     char password[30];
  63.     char username[30];
  64.     start:
  65.    printf("\t\t\t..............................................\n");
  66.     printf("\t\t\t\t\t[ADMIN LOGIN]                \n\n");
  67.     printf("\t\t\tEnter your username: ");
  68.     scanf("%s",username);
  69.      printf("\t\t\tEnter your password: ");
  70.     while(ch!=13)
  71.    {
  72.  ch=_getch();
  73.  
  74.  if(ch!=13){
  75.  putch('*');
  76.  password[i] = ch;
  77.  i++;
  78.  }
  79.    }
  80.    password[i] = '\0';
  81.  
  82.  
  83.     if(strcmp(username,"a")==0){
  84.  
  85.    if(strcmp(password,"b")==0)
  86.    {
  87.        printf("\n\n");
  88.        char loading[]="\t\t\t\tloading.....................................!!\n";
  89.         while(loading[i]!='\0')
  90.     {
  91.         Sleep(50);
  92.         printf("%c",loading[i]);
  93.         i++;
  94.     }
  95.  
  96.  
  97.         printf("\n                                      Login Success!!\n\n");
  98.         printf("\n                                Enter any key to continue! \n\n");
  99.         _getch();
  100.         mainMenu();
  101.     }
  102.    else{
  103.         printf("\n\n");
  104.        printf("\t\t\t..............................................\n");
  105.  
  106.     printf("\n                                      Wrong Password!!\n\n");
  107.     remsk:
  108.         printf("\n");
  109.     printf("\t\t\tWould you like to try again?[yes?/no?]: ");
  110.     scanf("%s",aa);
  111.  
  112.     if (strcmp(aa,"yes")==0)
  113.      {
  114.         system("cls");   //clears the screen before proceeding to the next step.
  115.       adminlogin();
  116.  
  117. }
  118.         if (strcmp(aa,"no")==0)
  119.         {
  120.            exit(0);
  121.         }
  122.         else if(1)
  123.         {
  124.             system("cls");
  125.             printf("\n");
  126.             printf("\t\t\tInvalid choice. Enter [yes/no] only!");
  127.             goto remsk;
  128.         }
  129.  
  130. }
  131.     }else{
  132.         printf("\n\n");
  133.        printf("\t\t\t..............................................\n");
  134.     printf("\n                                     User doesn't exist!\n\n\n\n");
  135.    goto remsk;
  136. }
  137.  
  138. _getch();
  139. mainMenu();
  140. }
  141.  
  142. //For Main Menu
  143. void mainMenu(){
  144.     system("color E");//yellow
  145.     system("cls");
  146.     printf("\t\t\t...........................................\n");
  147.     printf("\t\t\t:\t\t[MAIN MENU]\t          :\n");
  148.     printf("\t\t\t:.........................................:\n");
  149.     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");
  150.     printf("\t\t\tPress (1-7)\n");
  151.     printf("                       ..............................................\n");
  152.     switch(_getch()){
  153.         case '1': adduser();
  154.                   break;
  155.         case '2': listuser();
  156.                   break;
  157.         case '3': edituser();
  158.                   break;
  159.         case '4': deluser();
  160.                   break;
  161.         case '5': searchuser();
  162.                   break;
  163.         case '6': booksection();
  164.                   break;
  165.         case '7': exit(0);
  166.                   break;
  167.         default:
  168.  
  169.             printf("\nEnter any key to try again.");
  170.             _getch();
  171. system("cls");
  172.     mainMenu();
  173.  
  174.     }
  175. }
  176.  
  177. // For Adding New users
  178. void adduser(){
  179.  
  180.  
  181.  
  182.     struct profile b;
  183.      int i,g,j;
  184.     FILE *f;
  185.     f=fopen("frecord.txt","ab");
  186.     system("cls");
  187.     printf("\t\t\t...........................................\n");
  188.     printf("\t\t\t:\t\t[USER REGISTER]\t          :\n");
  189.      printf("\t\t\t...........................................\n");
  190.  
  191.  printf("\t\t\t\tEnter first and last name: ");
  192.     scanf("%s %s",b.firstname,b.lastname);
  193.       fflush(stdin);
  194. name1:
  195. strcat(b.firstname," ");
  196.    strcat(b.firstname,b.lastname);
  197.    for (j=0;b.firstname[j]!='\0';++j)
  198.       {
  199.    b.name[j]=b.firstname[j];
  200.       }
  201.       b.name[j]='\0';
  202.  
  203.    for (j=0;b.name[j]!='\0';++j)
  204.       {
  205.       if (b.name[j]>='0' && b.name[j]<='9')
  206.       {
  207.           printf("\n");
  208.           printf("\t\t\t\tInvalid name\n");
  209.            printf("\t\t\t\tEnter name again: ");
  210.     scanf("%s %s",b.firstname,b.lastname);
  211.       fflush(stdin);
  212.       goto name1;
  213.           break;
  214.       }
  215.       }
  216.  
  217.     printf("\t\t\t\tEnter address: ");
  218.     scanf("%s",&b.address);
  219.     fflush(stdin);
  220.     printf("\t\t\t\tEnter phone number: ");
  221.     scanf("%lld",&b.phoneNumber);
  222.     fflush(stdin);
  223.     chck:
  224.     if (b.phoneNumber<=9999999999 && b.phoneNumber>=99999999)
  225.     {
  226.  
  227.      printf("\t\t\t\tEnter UserID: ");
  228.     scanf("%d",&b.userID);
  229.     fflush(stdin);
  230.     }
  231.  
  232.     else
  233.     {
  234.         printf("\n\t\t\t\tInvalid phone number!\n");
  235.         printf("\t\t\t\tEnter new phone number: ");
  236.     scanf("%lld",&b.phoneNumber);
  237.     fflush(stdin);
  238.     goto chck;
  239.     }
  240.  
  241.          printf("                        ............................................\n");
  242.     fwrite(&b, sizeof(b), 1, f);
  243.      fclose(f);
  244.  
  245.       printf("\nRecord Saved!\n");
  246.  
  247.           printf("\n\n");
  248.       printf("Would you like to add more user? [y/n]: ");
  249.             readd:
  250.       i=_getch();
  251.       if (i=='y')
  252.             {
  253.           adduser();
  254.                 }
  255.         if (i=='n')
  256.             {
  257.      printf("\nEnter any key to go back!");
  258.     _getch();
  259.     system("cls");
  260.     mainMenu();
  261.                 }
  262.                 else if(1)
  263.                 {
  264.                   goto readd;
  265.                 }
  266.  
  267. }
  268.  
  269. //Listing users profile
  270. void listuser(){
  271.  
  272.  
  273.     struct profile b;
  274.  
  275.     FILE *f;
  276.     f=fopen("frecord.txt","rb"); //binary read mode
  277.     system("cls");
  278.     if (f==NULL){
  279.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  280.         getch();
  281.         mainMenu();
  282.     }
  283.     printf("\t\t\t..................................................\n");
  284.     printf("\t\t\t:\t\t[LIST USERS PROFILE]             :\n");
  285.     printf("\t\t\t:................................................:\n");
  286.  
  287.     while(fread(&b,sizeof(b),1,f)==1){
  288.     printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",b.name,b.address,b.phoneNumber,b.userID);
  289.     }
  290. printf("............................................\n");
  291.     fclose(f);
  292.  
  293.     printf("\nEnter any key to go back!");
  294.     _getch();
  295.     system("cls");
  296.     mainMenu();
  297. }
  298.  
  299. //Editing profile
  300. void edituser(){
  301.     int id;
  302.     int found;
  303.    int e,j;
  304.  
  305.  
  306.     printf("                        ............................................\n");
  307.     printf("\t\t\t\t\t  [EDIT USER]\n\n");
  308.  
  309.  
  310.     struct profile b;
  311.  
  312.     FILE *fp;
  313.     FILE *ftemp;
  314.     fp = fopen("frecord.txt","rb");
  315.     ftemp = fopen("ftemprecord.txt","wb");
  316.      system("cls");
  317.     printf("\t\t\tEnter Users ID to modify: ");
  318.     scanf("%d",&id);
  319.     fflush(stdin);
  320.   printf("\n");
  321.     while(fread(&b,sizeof(b),1,fp)==1){
  322.             if(id!=b.userID)
  323.                 fwrite(&b,sizeof(b),1,ftemp);
  324.             if(id==b.userID){
  325.                 found = 1;
  326.             }
  327.     }
  328.     if (found == 1){
  329.   printf("\t\t\t\tEnter first and last name: ");
  330.     scanf("%s %s",b.firstname,b.lastname);
  331.       fflush(stdin);
  332. name1:
  333. strcat(b.firstname," ");
  334.    strcat(b.firstname,b.lastname);
  335.    for (j=0;b.firstname[j]!='\0';++j)
  336.       {
  337.    b.name[j]=b.firstname[j];
  338.       }
  339.       b.name[j]='\0';
  340.  
  341.    for (j=0;b.name[j]!='\0';++j)
  342.       {
  343.       if (b.name[j]>='0' && b.name[j]<='9')
  344.       {
  345.           printf("\n");
  346.           printf("\t\t\t\tInvalid name\n");
  347.            printf("\t\t\t\tEnter name again: ");
  348.     scanf("%s %s",b.firstname,b.lastname);
  349.       fflush(stdin);
  350.       goto name1;
  351.           break;
  352.       }
  353.       }
  354.     printf("\t\t\t\tEnter address: ");
  355.     scanf("%s",&b.address);
  356.     fflush(stdin);
  357.     printf("\t\t\t\tEnter phone number: ");
  358.     scanf("%lld",&b.phoneNumber);
  359.     fflush(stdin);
  360.     chck:
  361.     if (b.phoneNumber<=9999999999 && b.phoneNumber>=9999999)
  362.     {
  363.      printf("\t\t\t\tEnter UserID: ");
  364.     scanf("%d",&b.userID);
  365.     fflush(stdin);
  366.     }
  367.     else
  368.     {
  369.         printf("\n\t\t\t\tInvalid phone number!\n");
  370.         printf("\t\t\t\tEnter new phone number: ");
  371.     scanf("%lld",&b.phoneNumber);
  372.     fflush(stdin);
  373.     goto chck;
  374.     }
  375.         fwrite(&b,sizeof(b),1,ftemp);
  376.     }else if(found!=1){
  377.         printf("The contact does not exist!");
  378.     }
  379.  
  380.  
  381.  
  382.     fclose(fp);
  383.     fclose(ftemp);
  384.     remove("frecord.txt");
  385.     rename("ftemprecord.txt","frecord.txt");
  386.  
  387.     printf("\n\nEnter any key to go back!");
  388.     _getch();
  389.     system("cls");
  390.  
  391.     mainMenu();
  392.  
  393. }
  394.  
  395. //Searching profile
  396. void searchuser(){
  397.     int id;
  398.     int de,c;
  399.     struct profile b;
  400.  
  401.     FILE *fp;
  402.     fp=fopen("frecord.txt","rb");
  403.  
  404.     system("cls");
  405.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  406.     printf("\t\t\t...........................................\n");
  407.     printf("\t\t\t:\t\t[SEARCH USER]\t          :\n");
  408.     printf("\t\t\t:.........................................:\n\n");
  409.     printf("\t\t\tEnter Users ID to search: ");
  410.     scanf("%d",&id);
  411.     printf("\n\n");
  412.     fflush(stdin);
  413. printf("\n");
  414.     while (fread(&b,sizeof(b),1,fp)==1)
  415.     {
  416.         if (id==b.userID){
  417.  
  418.         printf("\n[%s Profile ID]\n",b.name);
  419.     printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",b.name,b.address,b.phoneNumber,b.userID);
  420.     de=1;
  421. }
  422.     }
  423. if (de==1)
  424. {
  425.  
  426.     printf("\n\n");
  427.     printf("Would you like to search another user?[y/n]: ");
  428.      research:
  429.     c=_getch();
  430.     if (c=='y')
  431.     {
  432.         searchuser();
  433.             }
  434.             if (c=='n')
  435.             {
  436.                 printf("\n\n");
  437.               printf("\n\nEnter any key to go back!");
  438.  
  439.     _getch();
  440.     system("cls");
  441.     mainMenu();
  442.             }
  443.             else if(1)
  444.             {
  445.                 goto research;
  446.             }
  447.  
  448. }
  449. if (de!=1)
  450. {
  451.     printf("\t\t\t\t\t*INVALID USER*");
  452.     printf("\n\nEnter any key to go back!");
  453.  
  454.     _getch();
  455.     system("cls");
  456.     mainMenu();
  457.  
  458. }
  459. fclose(fp);
  460. }
  461.  
  462.  
  463.  
  464.  
  465. //Deleting profile
  466. void deluser(){
  467.     char name[20];
  468.     int recordExists,id;
  469.  
  470.     system("cls");
  471.     fflush(stdin);
  472.  
  473.     struct profile b;
  474.  
  475.     FILE *fp;
  476.     FILE *ftemp;
  477.  
  478.     fp = fopen("frecord.txt","r");
  479.     ftemp = fopen("ftemprecord.txt","w");
  480.  
  481.     printf("\t\t\t...........................................\n");
  482.     printf("\t\t\t:\t\t[DELETE USER]\t          :\n");
  483.     printf("\t\t\t:.........................................:\n\n");
  484.     printf("\t\t\tEnter Users ID to delete: ");
  485.     scanf("%d",&id);
  486.     fflush(stdin);
  487.     printf("\n");
  488.  
  489.     while (fread( &b, sizeof(b), 1, fp) == 1) {
  490.         if (id!=b.userID)
  491.           fwrite(&b, sizeof(b), 1, ftemp);
  492.         if (id==b.userID)
  493.           recordExists = 1;
  494.     }
  495.  
  496.     fclose(fp);
  497.     fclose(ftemp);
  498.  
  499.     if(recordExists!=1){
  500.         printf("The contact does not exist!");
  501.     }else{
  502.         remove("frecord.txt");
  503.         rename("ftemprecord.txt", "frecord.txt");
  504.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  505.     }
  506.  
  507.     printf("\n\nEnter any key to go back!");
  508.     _getch();
  509.     system("cls");
  510.  
  511.     mainMenu();
  512. }
  513.  
  514. void booksection()
  515. {
  516.      system("cls");
  517.      system("color A");
  518.     printf("\t\t\t.............................................\n");
  519.     printf("\t\t\t:\t\t[BOOK SECTION]\t            :\n");
  520.     printf("\t\t\t:...........................................:\n\n");
  521.     printf("\t\t\t1.Add book\n\t\t\t2.List Book\n\t\t\t3.Search Book\n\t\t\t4.Delete book\n\t\t\t5.Edit Book\n\t\t\t6.Issue Book\n\t\t\t7.Exit\n\t\t\t8.Go back\n");
  522.     printf("\t\t\tPress (1-8)\n");
  523.     printf("                       ..............................................\n");
  524.  
  525.     switch(_getch()){
  526.         case '1': addbook();
  527.                   break;
  528.  
  529.         case '2':listbook();
  530.                   break;
  531.  
  532.         case '7':exit(0);
  533.                   break;
  534.  
  535.         case '8': mainMenu();
  536.                  break;
  537.         default:
  538.  
  539.             printf("\nEnter any key to try again.");
  540.             _getch();
  541. system("cls");
  542. booksection();
  543. }
  544. }
  545. //add books in the library
  546. void addbook()
  547. {
  548.  
  549.     char m[20];
  550.  
  551. struct books d;
  552.  
  553.     FILE *fb;
  554.     fb=fopen("booksection.txt","ab");
  555.     system("cls");
  556.     printf("\t\t\t...........................................\n");
  557.     printf("\t\t\t:\t\t[ADD BOOKS]\t          :\n");
  558.     printf("\t\t\t:.........................................:\n\n");
  559.     printf("\t\t\tEnter the name of the book to be added: ");
  560.     scanf("%s",d.bookname);
  561.     fflush(stdin);
  562.     printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
  563.     printf("\t\t\t\tEnter day: ");
  564.    scanf("%lld",&d.day);
  565.     dete:
  566.    if (d.day>=0 && d.day<=32)
  567.     {
  568.          printf("\t\t\t\tEnter month: ");
  569.    scanf("%lld",&d.month);
  570.     fflush(stdin);
  571.  
  572.     dete2:
  573.      if (d.month>=0 && d.month<=12)
  574.          {
  575.     printf("\t\t\t\tEnter year: ");
  576.     scanf("%lld",&d.year);
  577.    fflush(stdin);
  578.    dete3:
  579.      if (d.year>2018 && d.day<2020)
  580.      {
  581.          printf("\t\t\t\tEnter Book Id:");
  582.          scanf("%d",&d.bookID);
  583.      }
  584.          else
  585.          {
  586.              printf("\n");
  587.              printf("\t\t\t\tInvalid entry!!\n");
  588.     printf("\t\t\t\tEnter year again: ");
  589.    scanf("%lld",&d.year);
  590.    goto dete3;
  591.  
  592.     }
  593.          }
  594.  
  595.    else
  596. {
  597.      printf("\n");
  598.        printf("\t\t\t\tInvalid entry!!\n");
  599.     printf("\t\t\t\tEnter month again: ");
  600.    scanf("%lld",&d.month);
  601.    goto dete2;
  602. }
  603.     }
  604.  
  605.     else{
  606.  printf("\n");
  607.        printf("\t\t\t\tInvalid entry!!\n");
  608.     printf("\t\t\t\tEnter day again: ");
  609.    scanf("%lld",&d.day);
  610.    goto dete;
  611.     }
  612.  
  613.  
  614.  
  615.     printf("                        ............................................\n");
  616.     fwrite(&d,sizeof(d),1,fb);
  617.     fclose(fb);
  618.  
  619.     printf("\n\t\t\tRecord Saved\n\n!");
  620.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  621.     scanf("%s",m);
  622.     if (strcmp(m,"main")==0)
  623.     {
  624.         system("cls");
  625.         mainMenu();
  626.     }
  627.     else if (1)
  628.     {
  629.     system("cls");
  630.    booksection();
  631.     }
  632. }
  633.  
  634. void listbook()
  635. {
  636.  struct books d;
  637.  
  638.     FILE *fb;
  639.     fb=fopen("booksection.txt","r"); //binary read mode
  640.     system("cls");
  641.     if (fb==NULL){
  642.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  643.         getch();
  644.         booksection();
  645.     }
  646.     printf("\t\t\t..................................................\n");
  647.     printf("\t\t\t:\t\t   [LIST BOOKS]                  :\n");
  648.     printf("\t\t\t:................................................:\n");
  649.  
  650.     while(fread(&d,sizeof(d),1,fb)==1){
  651.     printf("\nBook Name: %s\nIssue date: %lld/ %lld/ %lld\nBook ID: %d\n\n",d.bookname,d.day,d.month,d.year,d.bookID);
  652.     }
  653. printf("............................................\n");
  654.     fclose(fb);
  655.  
  656.     printf("\nEnter any key to go back!");
  657.     _getch();
  658.     system("cls");
  659.     booksection();
  660. }
  661. //edit book information
  662. void editbook(){
  663.     char m[20];
  664.     int bookid;
  665.     int bfound;
  666.    int be;
  667.  
  668.  
  669.     printf("                        ............................................\n");
  670.     printf("\t\t\t\t\t  [EDIT BOOK]\n\n");
  671.  
  672.  
  673.    struct books d;
  674.  
  675.     FILE *fb;
  676.     FILE *fbtemp;
  677.     fb=fopen("booksection.txt","r"); //binary read mode
  678.  
  679.     fbtemp = fopen("fbtemprecord.txt","w");
  680.      system("cls");
  681.     printf("\t\t\tEnter BOOK ID to modify: ");
  682.     scanf("%d",&bookid);
  683.     fflush(stdin);
  684.   printf("\n");
  685.     while(fread(&d,sizeof(d),1,fb)==1){
  686.             if(bookid!=d.bookID)
  687.                 fwrite(&d,sizeof(d),1,fbtemp);
  688.             if(bookid==d.bookID){
  689.                 bfound = 1;
  690.             }
  691.     }
  692.     if (bfound == 1){
  693.     printf("\t\t\tEnter the name of the book to be added: ");
  694.     scanf("%s",d.bookname);
  695.     fflush(stdin);
  696.     printf("\t\t\t\tEnter date(dd/mm/yy):\n");
  697.     printf("\t\t\t\tEnter day: ");
  698.    scanf("%lld",&d.day);
  699.     dete:
  700.    if (d.day>=0 && d.day<=32)
  701.     {
  702.          printf("\t\t\t\tEnter month: ");
  703.    scanf("%lld",&d.month);
  704.     fflush(stdin);
  705.  
  706.     dete2:
  707.      if (d.month>=0 && d.month<=12)
  708.          {
  709.     printf("\t\t\t\tEnter year: ");
  710.     scanf("%lld",&d.year);
  711.    fflush(stdin);
  712.    dete3:
  713.      if (d.year>2018 && d.year <2020)
  714.      {
  715.          printf("\t\t\t\tEnter Book Id:");
  716.          scanf("%d",&d.bookID);
  717.      }
  718.          else
  719.          {
  720.              printf("\n");
  721.              printf("\t\t\t\tInvalid entry!!\n");
  722.     printf("\t\t\t\tEnter year again: ");
  723.    scanf("%lld",&d.year);
  724.    goto dete3;
  725.  
  726.     }
  727.          }
  728.  
  729.    else
  730. {
  731.      printf("\n");
  732.        printf("\t\t\t\tInvalid entry!!\n");
  733.     printf("\t\t\t\tEnter month again: ");
  734.    scanf("%lld",&d.month);
  735.    goto dete2;
  736. }
  737.     }
  738.  
  739.     else{
  740.  printf("\n");
  741.        printf("\t\t\t\tInvalid entry!!\n");
  742.     printf("\t\t\t\tEnter day again: ");
  743.    scanf("%lld",&d.day);
  744.    goto dete;
  745.     }
  746.  
  747.  
  748.         fwrite(&d,sizeof(d),1,fbtemp);
  749.     }else if(bfound!=1){
  750.         printf("\t\t\tThe book ID does not exist!");
  751.     }
  752.  
  753.  
  754.  
  755.     fclose(fb);
  756.     fclose(fbtemp);
  757.     remove("booksection.txt");
  758.     rename("fbtemprecord.txt","booksection.txt");
  759. printf("\n\n");
  760.    printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  761.     scanf("%s",m);
  762.     if (strcmp(m,"main")==0)
  763.     {
  764.         system("cls");
  765.         mainMenu();
  766.     }
  767.     else if (1)
  768.     {
  769.     system("cls");
  770.    booksection();
  771.     }
  772. }
  773.  
  774.  
  775.  
  776.  
  777.  
  778. void searchbook(){
  779.     char m[20];
  780.     int bid;
  781.     int bde,bc;
  782.     struct books d;
  783.  
  784.     FILE *fb;
  785.   fb=fopen("booksection.txt","r");
  786.  
  787.     system("cls");
  788.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  789.     printf("\t\t\t...........................................\n");
  790.     printf("\t\t\t:\t\t[SEARCH BOOK]\t          :\n");
  791.     printf("\t\t\t:.........................................:\n\n");
  792.     printf("\t\t\tEnter BOOK ID to search: ");
  793.     scanf("%d",&bid);
  794.     printf("\n\n");
  795.     fflush(stdin);
  796. printf("\n");
  797.     while (fread(&d,sizeof(d),1,fb)==1)
  798.     {
  799.         if (bid==d.bookID){
  800.  
  801.         printf("\n[%s Book Info]\n",d.bookname);
  802.    printf("\nBook Name: %s\nDate(dd/mm/yy): %lld/ %lld/ %lld\nBook ID: %d\n\n",d.bookname,d.day,d.month,d.year,d.bookID);
  803.     bde=1;
  804. }
  805.     }
  806. if (bde==1)
  807. {
  808.  
  809.     printf("\n\n");
  810.     printf("Would you like to search another book?[y/n]: ");
  811.      research:
  812.     bc=_getch();
  813.     if (bc=='y')
  814.     {
  815.         searchuser();
  816.             }
  817.             if (bc=='n')
  818.             {
  819.                 printf("\n\n");
  820.               printf("\n\nEnter any key to go back!");
  821.  
  822.     _getch();
  823.     system("cls");
  824.     booksection();
  825.             }
  826.             else if(1)
  827.             {
  828.                 goto research;
  829.             }
  830.  
  831. }
  832. if (bde!=1)
  833. {
  834.     printf("\t\t\t\t\t*INVALID BOOK ID*");
  835.     printf("\n\n");
  836.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  837.     scanf("%s",m);
  838.     if (strcmp(m,"main")==0)
  839.     {
  840.         system("cls");
  841.         mainMenu();
  842.     }
  843.     else if (1)
  844.     {
  845.     system("cls");
  846.    booksection();
  847.     }
  848. }
  849. fclose(fb);
  850. }
  851.  
  852.  
  853.  
  854. void delbook(){
  855.     char m[20];
  856.     char bname[20];
  857.     int brecordExists,bid;
  858.  
  859.     system("cls");
  860.     fflush(stdin);
  861.  
  862.     struct books d;
  863.  
  864.     FILE *fb;
  865.     FILE *fbtemp;
  866.  
  867.    fb=fopen("booksection.txt","r");
  868.     fbtemp = fopen("fbtemprecord.txt","w");
  869.  
  870.     printf("\t\t\t...........................................\n");
  871.     printf("\t\t\t:\t\t[DELETE BOOK]\t          :\n");
  872.     printf("\t\t\t:.........................................:\n\n");
  873.     printf("\t\t\tEnter Book ID to delete: ");
  874.     scanf("%d",&bid);
  875.     fflush(stdin);
  876.     printf("\n");
  877.  
  878.     while (fread( &d, sizeof(d), 1, fb) == 1) {
  879.         if (bid!=d.bookID)
  880.           fwrite(&d, sizeof(d), 1, fbtemp);
  881.         if (bid==d.bookID)
  882.           brecordExists = 1;
  883.     }
  884.  
  885.     fclose(fb);
  886.     fclose(fbtemp);
  887.  
  888.     if(brecordExists!=1){
  889.         printf("\t\t\tThe book does not exist!");
  890.     }else{
  891.         remove("booksection.txt");
  892.         rename("fbtemprecord.txt", "booksection.txt");
  893.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  894.     }
  895. printf("\n\n");
  896.   printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  897.     scanf("%s",m);
  898.     if (strcmp(m,"main")==0)
  899.     {
  900.         system("cls");
  901.         mainMenu();
  902.     }
  903.     else if (1)
  904.     {
  905.     system("cls");
  906.    booksection();
  907.     }
  908. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement