Guest User

Untitled

a guest
Dec 2nd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5.  
  6.  
  7.  
  8. typedef struct client{
  9. int ID;
  10. char PW[100],NAME[100],ADDRESS[100],PNUM[100];
  11. struct client* next;
  12. }client;
  13.  
  14. typedef struct book
  15. {
  16. int book_num;
  17. char book_name[50];
  18. char publisher[50];
  19. char author[20];
  20. long long ISBN;
  21. char book_address[50];
  22. char Y_N[2];
  23. struct book *next;
  24. }book;
  25.  
  26. typedef struct Borrow
  27. {
  28. int stu_num;
  29. int book_num;
  30. time_t b_date;
  31. time_t r_date;
  32. struct Borrow *next;
  33. } borrow;
  34.  
  35. int temp1;
  36. int IDD;
  37. /////////register/////////
  38. client* create_linkedlist_client(int n);
  39. int line_of_file(char* name);
  40.  
  41. void download_linkedlist_client(client* head);
  42. void duplicate_inspection_client(client* head);
  43. void sort_linkedlist_client(client* head);
  44. void upload_linkedlist_client(client* head);
  45. void change_my_info(client* head,int n);
  46. void withdrawal(client* head,int n);
  47.  
  48. //////////login///////////
  49. int login(client* head,int id,char* pw);
  50. client* create_linkedlist_client_login(int n);
  51.  
  52. ////////book///////////
  53. book* create_linkedlist_book(int n);
  54. void download_linkedlist_book(book* head);
  55. void duplicate_inspection_book(book* head);
  56. void sort_linkedlist_book(book* head);
  57. void upload_linkedlist_book(book* head);
  58.  
  59. void search_linkedlist_book_ISBN(book* head);
  60. void search_linkedlist_book_bookname(book* head);
  61. void search_linkedlist_book_publisher(book* head);
  62. void search_linkedlist_book_author(book* head);
  63. void search_linkedlist_book_all(book* head);
  64.  
  65. ////////////////////////////////////////
  66.  
  67. void Register_linkedlist_book(int booknum,book* head);
  68. int Readbookname_linkedlist_book(book* head,int length);
  69. void delete_linkedlist_book(book* head);
  70. client* create_NOINPUT_linkedlist_client(int n);
  71. client* search_by_clientname(client* head);
  72. client* search_by_ID(client* head);
  73. client* Print_all_client(client* head);
  74. /////////////////////////////////////////////////
  75. int identifier=0;
  76.  
  77. // main start
  78. int main()
  79. {
  80. client* HEAD=NULL;
  81. client* CLIENT=NULL;
  82. book* head=NULL;
  83.  
  84. int servicestart;
  85.  
  86. while(1)
  87. {
  88. system("clear");
  89. puts(">>Library Service<<\n1.Register 2.Login 3.Exit Program");
  90. scanf("%d",&servicestart);
  91.  
  92.  
  93.  
  94. switch(servicestart)
  95. {
  96.  
  97.  
  98. case 1:
  99. {
  100.  
  101. identifier=0;
  102. system("clear");
  103.  
  104. puts("You selected Register");
  105. puts("Enter Student ID | Password | Name | Address | Phonenumber");
  106. puts("ex)20180345|ssu2018|DanielHong|KEPCO,Gaepo-dong,Gangnam-gu,seoul|01031414473");
  107. printf("\n\n");
  108.  
  109.  
  110. HEAD=create_linkedlist_client(line_of_file("client.txt")+1); //Create , INPUT VALUES.
  111. download_linkedlist_client(HEAD);
  112. duplicate_inspection_client(HEAD);
  113. if(identifier==0)
  114. {
  115. sort_linkedlist_client(HEAD);
  116. upload_linkedlist_client(HEAD);
  117. }
  118.  
  119. break;
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126. case 2:
  127. {
  128. int IDD;
  129. int login_identifier;
  130. char PW[100];
  131. int admin_identifier_int;
  132. char admin_identifier_string[10];
  133. int break_or_admin=0;
  134.  
  135. while(1)
  136. {
  137. system("clear");
  138. puts(">>Login<<");
  139.  
  140. fputs("ID:",stdout);
  141. admin_identifier_int=scanf("%d",&IDD);
  142.  
  143.  
  144. if (admin_identifier_int != 1) //string
  145. {
  146. system("clear");
  147. puts("Did you entered string?");
  148. puts("If you enter admin , connected with administrator authority");
  149. puts("If you enter other string , goes back to main menu");
  150. while(getchar() !='\n'); //clean input buffer,beacuse of scanf error.
  151. scanf("%s",admin_identifier_string);
  152. if(strcmp(admin_identifier_string,"admin")==0)
  153. {
  154. break_or_admin=1;
  155. break;
  156. }
  157.  
  158. else
  159. {
  160. break_or_admin=0;
  161. break;
  162. }
  163.  
  164. }
  165.  
  166.  
  167.  
  168. fputs("PW:",stdout);
  169. scanf("%s",PW);
  170.  
  171. HEAD=create_linkedlist_client_login(line_of_file("client.txt"));
  172. download_linkedlist_client(HEAD);
  173. login_identifier=login(HEAD,IDD,PW);
  174.  
  175. if(login_identifier==0) //Wrong
  176. {
  177. system("clear");
  178. puts("Wrong ID or PW");
  179. puts("Try again in 3sec");
  180. Sleep(3000);
  181. }
  182.  
  183.  
  184. if(login_identifier==1) //Pass
  185. break;
  186.  
  187.  
  188.  
  189. }
  190.  
  191.  
  192. if(login_identifier==1 && break_or_admin!=1)
  193. {
  194. while(1)
  195. {
  196.  
  197. head=create_linkedlist_book(line_of_file("book.txt"));
  198. download_linkedlist_book(head);
  199.  
  200. system("clear");
  201. int input=0;
  202. puts(">>>MENU<<<");
  203. puts("1.Search book 2.My borrow list 3.Edit personal information");
  204. puts("4.Membership withdrawal 5.Logout 6.Exit program");
  205. scanf("%d",&input);
  206.  
  207. switch(input)
  208. {
  209. case 1:
  210. {
  211.  
  212. int menuselect=0;
  213. system("clear");
  214. puts("1.Search with book name 2.Search with publisher 3.Search with ISBN");
  215. puts("4.Search with author 5.search all 6.previous menu");
  216. scanf("%d",&menuselect);
  217.  
  218. switch(menuselect)
  219. {
  220. case 1:
  221. {
  222. search_linkedlist_book_bookname(head);
  223. break;
  224. }
  225. case 2:
  226. {
  227. search_linkedlist_book_publisher(head);
  228. break;
  229. }
  230. case 3:
  231. {
  232. search_linkedlist_book_ISBN(head);
  233. break;
  234. }
  235. case 4:
  236. {
  237. search_linkedlist_book_author(head);
  238. break;
  239. }
  240. case 5:
  241. {
  242. search_linkedlist_book_all(head);
  243. break;
  244. }
  245. case 6:
  246. {
  247. break;
  248. }
  249. }
  250.  
  251. break;
  252. }
  253.  
  254.  
  255. case 2:
  256. {
  257. break;
  258. }
  259.  
  260. case 3:
  261. {
  262. HEAD=create_linkedlist_client_login(line_of_file("client.txt"));
  263. download_linkedlist_client(HEAD);
  264. sort_linkedlist_client(HEAD);
  265. change_my_info(HEAD,IDD);
  266. }
  267.  
  268. case 4:
  269. {
  270. HEAD=create_linkedlist_client_login(line_of_file("client.txt"));
  271. download_linkedlist_client(HEAD);
  272. sort_linkedlist_client(HEAD);
  273. withdrawal(HEAD,IDD);
  274. }
  275. case 5:
  276. {
  277. break;
  278. }
  279. case 6:
  280. {
  281. return 0;
  282. }
  283.  
  284.  
  285.  
  286.  
  287. }
  288. if(input==5)
  289. break;
  290.  
  291. } //while
  292.  
  293. } //if
  294.  
  295.  
  296.  
  297. if(break_or_admin==1)
  298. {
  299.  
  300. while(1)
  301. {
  302. int foradmin=0;
  303. system("clear");
  304. puts("1.Register book 2.Delete book 3.Borrow book");
  305. puts("4.Return book 5.Search book 6.Member list");
  306. puts("7.Logout 8.Exit program");
  307. int booknum;
  308. scanf("%d",&foradmin);
  309. switch(foradmin)
  310. {
  311. case 1:
  312. {
  313. head=create_linkedlist_book(line_of_file("book.txt"));
  314. download_linkedlist_book(head);
  315. sort_linkedlist_book(head);
  316. //upload_linkedlist_book(head);
  317. booknum=Readbookname_linkedlist_book(head,line_of_file("book.txt"));
  318. Register_linkedlist_book(booknum,head);
  319. head=create_linkedlist_book(line_of_file("book.txt"));
  320. download_linkedlist_book(head);
  321. sort_linkedlist_book(head);
  322. upload_linkedlist_book(head);
  323.  
  324.  
  325. break;
  326. }
  327.  
  328. case 2:
  329. {
  330.  
  331. head=create_linkedlist_book(line_of_file("book.txt"));
  332. download_linkedlist_book(head);
  333. sort_linkedlist_book(head);
  334. delete_linkedlist_book(head);
  335. break;
  336. }
  337. case 3:
  338. {
  339. break;
  340. }
  341. case 4:
  342. {
  343. break;
  344. }
  345. case 5:
  346. {
  347. int menuselect=0;
  348. system("clear");
  349. puts("1.Search with book name 2.Search with publisher 3.Search with ISBN");
  350. puts("4.Search with author 5.search all 6.previous menu");
  351. scanf("%d",&menuselect);
  352.  
  353. switch(menuselect)
  354. {
  355. case 1:
  356. {
  357. search_linkedlist_book_bookname(head);
  358. break;
  359. }
  360. case 2:
  361. {
  362. search_linkedlist_book_publisher(head);
  363. break;
  364. }
  365. case 3:
  366. {
  367. search_linkedlist_book_ISBN(head);
  368. break;
  369. }
  370. case 4:
  371. {
  372. search_linkedlist_book_author(head);
  373. break;
  374. }
  375. case 5:
  376. {
  377. search_linkedlist_book_all(head);
  378. break;
  379. }
  380. case 6:
  381. {
  382. break;
  383. }
  384. }
  385.  
  386. break;
  387. }
  388.  
  389.  
  390.  
  391. case 6:
  392. {
  393. int forclient=0;
  394. system("clear");
  395. puts(">>>>>>>>>LIST OF CLIENTS<<<<<<<<<<");
  396. puts("1.Search with name 2.Search with ID");
  397. puts("3.Print all 4.Previous menu");
  398. scanf("%d",&forclient);
  399. if(forclient==1)
  400. {
  401.  
  402. CLIENT=create_NOINPUT_linkedlist_client(line_of_file("client.txt")); //Create , INPUT VALUES.
  403. download_linkedlist_client(CLIENT);
  404. sort_linkedlist_client(CLIENT);
  405. upload_linkedlist_client(CLIENT);
  406. search_by_clientname(CLIENT);
  407.  
  408. }
  409.  
  410. if(forclient==2)
  411. {
  412. CLIENT=create_NOINPUT_linkedlist_client(line_of_file("client.txt")); //Create , INPUT VALUES.
  413. download_linkedlist_client(CLIENT);
  414. sort_linkedlist_client(CLIENT);
  415. upload_linkedlist_client(CLIENT);
  416. search_by_ID(CLIENT);
  417. }
  418.  
  419. if(forclient==3)
  420. {
  421. CLIENT=create_NOINPUT_linkedlist_client(line_of_file("client.txt")); //Create , INPUT VALUES.
  422. download_linkedlist_client(CLIENT);
  423. sort_linkedlist_client(CLIENT);
  424. upload_linkedlist_client(CLIENT);
  425. Print_all_client(CLIENT);
  426. }
  427.  
  428. if(forclient==4)
  429. {
  430. break;
  431. }
  432.  
  433.  
  434. break;
  435. }
  436.  
  437. case 7:
  438. {
  439. break;
  440. }
  441. case 8:
  442. {
  443. return 0;
  444. }
  445.  
  446.  
  447.  
  448. }
  449. if(foradmin==7)
  450. break;
  451.  
  452. }//while
  453.  
  454. } //if
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462. break;
  463. }//case2
  464.  
  465. case 3:
  466. break;
  467.  
  468.  
  469. }//switch
  470.  
  471. }//while
  472.  
  473. return 0;
  474. }//main
  475.  
  476. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  477. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  478. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  479.  
  480.  
  481. client* create_linkedlist_client(int n)
  482. {
  483.  
  484. client* head=NULL;
  485. client* temp=NULL;
  486. client* p = NULL;
  487.  
  488. char temp2[100],temp3[100],temp4[100],temp5[100];
  489. int i;
  490.  
  491. scanf("%d|%[^|]|%[^|]|%[^|]|%s",&temp1,temp2,temp3,temp4,temp5);
  492.  
  493. for(i=0;i<n;i++)
  494. {
  495. temp =(client*)malloc(sizeof(client));
  496.  
  497.  
  498. temp->ID=temp1; strcpy(temp->PW,temp2); strcpy(temp->NAME,temp3);
  499. strcpy(temp->ADDRESS,temp4); strcpy(temp->PNUM,temp5);
  500.  
  501. temp->next=NULL;
  502.  
  503.  
  504.  
  505. if(head==NULL)
  506. {
  507. head=temp;
  508. }
  509. else
  510. {
  511. p=head;
  512. while(p->next != NULL)
  513. p=p->next;
  514. p->next = temp;
  515. }
  516. }
  517. return head;
  518. }
  519.  
  520.  
  521.  
  522. void upload_linkedlist_client(client* head)
  523. {
  524. client* p=head;
  525. FILE *f=fopen("client.txt","w");
  526.  
  527. while(p !=NULL)
  528. {
  529. fprintf(f,"%d|%s|%s|%s|%s\n",p->ID,p->PW,p->NAME,p->ADDRESS,p->PNUM);
  530. p = p->next;
  531. }
  532. fclose(f);
  533. }
  534.  
  535.  
  536.  
  537.  
  538. void download_linkedlist_client(client* head)
  539. {
  540. client* p=head;
  541. FILE *f=fopen("client.txt","r");
  542.  
  543. while(p !=NULL)
  544. {
  545. fscanf(f,"%d|%[^|]|%[^|]|%[^|]|%s\n",&(p->ID),p->PW,p->NAME,p->ADDRESS,p->PNUM);
  546. p = p->next;
  547. }
  548. fclose(f);
  549. }
  550.  
  551. void sort_linkedlist_client(client* head)
  552. {
  553. client *i,*j;
  554. int temp1;
  555. char temp2[100],temp3[100],temp4[100],temp5[100];
  556.  
  557. for(i=head;i->next!=NULL;i=i->next)
  558. {
  559. for(j=i->next; j!=NULL; j=j->next)
  560. {
  561. if(i->ID > j->ID)
  562. {
  563. temp1 = i->ID;
  564. strcpy(temp2,i->PW); strcpy(temp3,i->NAME); strcpy(temp4,i->ADDRESS); strcpy(temp5,i->PNUM);
  565. i->ID=j->ID;
  566. strcpy(i->PW,j->PW); strcpy(i->NAME,j->NAME); strcpy(i->ADDRESS,j->ADDRESS); strcpy(i->PNUM,j->PNUM);
  567. j->ID=temp1; strcpy(j->PW,temp2); strcpy(j->NAME,temp3); strcpy(j->ADDRESS,temp4); strcpy(j->PNUM,temp5);
  568. }
  569. }
  570. }
  571. }
  572.  
  573.  
  574.  
  575.  
  576.  
  577. int line_of_file(char * name)
  578. {
  579. FILE *fp;
  580. char buf[1024];
  581. int i;
  582.  
  583. fp=fopen(name ,"r");
  584. for (i=0,buf[1022]=0; fgets(buf,1024,fp); buf[1022]=0)
  585. (buf[1022] && buf[1022] != '\n') ? : i++;
  586.  
  587. fclose(fp);
  588. return i;
  589. }
  590.  
  591.  
  592. void duplicate_inspection_client(client* head)
  593. {
  594.  
  595. client* p=head;
  596.  
  597. while(p->next!=NULL)
  598. {
  599. if(temp1 == p->ID)
  600. {
  601. system("clear");
  602. puts("ERROR!! Have a Same ID");
  603. puts("Going back to main menu in 5sec...");
  604. identifier=1;
  605. Sleep(5000);
  606. break;
  607. }
  608.  
  609. p = p->next;
  610. }
  611.  
  612. }
  613.  
  614.  
  615. int login(client* head,int id,char* pw)
  616. {
  617.  
  618. client* p=head;
  619.  
  620. while(p != NULL)
  621. {
  622.  
  623. if((id == p->ID)==1 && strcmp(pw,p->PW)==0)
  624. return 1;
  625.  
  626.  
  627. p = p->next;
  628.  
  629. }
  630. return 0;
  631. }
  632.  
  633. client* create_linkedlist_client_login(int n)
  634. {
  635.  
  636. int i;
  637. client* head=NULL;
  638. client* temp=NULL;
  639. client* p = NULL;
  640.  
  641. for(i=0;i<n;i++)
  642. {
  643. temp =(client*)malloc(sizeof(client));
  644. temp->next=NULL;
  645.  
  646. if(head==NULL)
  647. {
  648. head=temp;
  649. }
  650. else
  651. {
  652. p=head;
  653. while(p->next != NULL)
  654. p=p->next;
  655. p->next = temp;
  656. }
  657. }
  658. return head;
  659. }
  660.  
  661.  
  662. void change_my_info(client* head,int n)
  663. {
  664. client* p=head;
  665.  
  666. char tempPW[100],tempADDRESS[100],tempPNUM[100];
  667.  
  668. system("clear");
  669. puts("Enter new PW");
  670. while(getchar()!='\n');
  671. scanf("%[^\n]",tempPW);
  672. puts("Enter new ADDRESS");
  673. while(getchar()!='\n');
  674. scanf("%[^\n]",tempADDRESS);
  675. puts("Enter new PNUM");
  676. while(getchar()!='\n');
  677. scanf("%[^\n]",tempPNUM);
  678.  
  679. FILE* f=fopen("client.txt","w");
  680. while(p!=NULL)
  681. {
  682. if(n==p->ID)
  683. fprintf(f,"%d|%s|%s|%s|%s\n",p->ID,tempPW,p->NAME,tempADDRESS,tempPNUM);
  684. if(n!=p->ID)
  685. fprintf(f,"%d|%s|%s|%s|%s\n",p->ID,p->PW,p->NAME,p->ADDRESS,p->PNUM);
  686.  
  687. p=p->next;
  688. }
  689.  
  690. fclose(f);
  691. }
  692.  
  693. void withdrawal(client* head,int n)
  694. {
  695. int repeat_value=1;
  696.  
  697. client* p=head;
  698.  
  699. while(1)
  700. {
  701. if(p->ID==n)
  702. {
  703.  
  704. printf("%d|%s|%s|%s|%s\n",p->ID,p->PW,p->NAME,p->ADDRESS,p->PNUM);
  705. puts("Delete in 5sec");
  706. Sleep(5000);
  707.  
  708. p=head;
  709.  
  710. FILE* f=fopen("client.txt","w");
  711. int i=1;
  712. while(p!=NULL)
  713. {
  714.  
  715. if(i!=repeat_value)
  716. fprintf(f,"%d|%s|%s|%s|%s\n",p->ID,p->PW,p->NAME,p->ADDRESS,p->PNUM);
  717.  
  718. ++i;
  719. p=p->next;
  720. }
  721. fclose(f);
  722. break;
  723. }
  724. repeat_value++;
  725. p=p->next;
  726. }
  727.  
  728.  
  729. }
  730.  
  731.  
  732.  
  733. ///////////////////////////////////////////////////////////////////////////////////////////////
  734.  
  735. void search_linkedlist_book_ISBN(book* head)
  736. {
  737. long long tempforISBN;
  738. int ISBN_identifier=0;
  739. system("clear");
  740. book* p=head;
  741. puts("Enter ISBN");
  742. scanf("%lld",&tempforISBN);
  743. system("clear");
  744. while(p != NULL)
  745. {
  746. if(tempforISBN == p->ISBN)
  747. {
  748.  
  749. printf("%d|%s|%s|%s|%lld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  750. ISBN_identifier=1;
  751.  
  752. }
  753.  
  754. p = p->next;
  755. }
  756.  
  757. if(ISBN_identifier==0)
  758. {
  759. system("clear");
  760. puts("Wrong! Going back to menu in 3sec");
  761. Sleep(3000);
  762. }
  763. if(ISBN_identifier==1)
  764. {
  765. puts("Going back to menu in 5sec");
  766. Sleep(5000);
  767. }
  768.  
  769. }
  770.  
  771.  
  772.  
  773. void search_linkedlist_book_bookname(book* head)
  774. {
  775. char tempforbookname[50];
  776. int bookname_identifier=0;
  777. system("clear");
  778. book* p=head;
  779. puts("Enter bookname");
  780. while(getchar()!='\n');
  781. scanf("%[^\n]",tempforbookname);
  782. system("clear");
  783. while(p != NULL)
  784. {
  785. if(strcmp(tempforbookname,p->book_name)==0)
  786. {
  787.  
  788. printf("%d|%s|%s|%s|%lld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  789. bookname_identifier=1;
  790.  
  791. }
  792.  
  793. p = p->next;
  794. }
  795.  
  796.  
  797. if(bookname_identifier==0)
  798. {
  799. system("clear");
  800. puts("Wrong! Going back to menu in 3sec");
  801. Sleep(3000);
  802. }
  803. if(bookname_identifier==1)
  804. {
  805. puts("Going back to menu in 5sec");
  806. Sleep(5000);
  807. }
  808.  
  809. }
  810.  
  811. void search_linkedlist_book_publisher(book* head)
  812. {
  813. char temp_book_publisher[50];
  814. int bookpublisher_identifier=0;
  815. system("clear");
  816. book* p=head;
  817. puts("Enter publisher");
  818. while(getchar()!='\n');
  819. scanf("%[^\n]",temp_book_publisher);
  820. system("clear");
  821. while(p != NULL)
  822. {
  823. if(strcmp(temp_book_publisher,p->publisher)==0)
  824. {
  825.  
  826. printf("%d|%s|%s|%s|%lld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  827. bookpublisher_identifier=1;
  828.  
  829. }
  830.  
  831. p = p->next;
  832. }
  833.  
  834.  
  835. if(bookpublisher_identifier==0)
  836. {
  837. system("clear");
  838. puts("Wrong! Going back to menu in 3sec");
  839. Sleep(3000);
  840. }
  841. if(bookpublisher_identifier==1)
  842. {
  843. puts("Going back to menu in 5sec");
  844. Sleep(5000);
  845. }
  846.  
  847. }
  848.  
  849.  
  850. void search_linkedlist_book_author(book* head)
  851. {
  852. char tempforbookauthor[50];
  853. int bookauthor_identifier=0;
  854. system("clear");
  855. book* p=head;
  856. puts("Enter bookname");
  857. while(getchar()!='\n');
  858. scanf("%[^\n]",tempforbookauthor);
  859. system("clear");
  860. while(p != NULL)
  861. {
  862. if(strcmp(tempforbookauthor,p->author)==0)
  863. {
  864.  
  865. printf("%d|%s|%s|%s|%lld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  866. bookauthor_identifier=1;
  867.  
  868. }
  869.  
  870. p = p->next;
  871. }
  872.  
  873.  
  874. if(bookauthor_identifier==0)
  875. {
  876. system("clear");
  877. puts("Wrong! Going back to menu in 3sec");
  878. Sleep(3000);
  879. }
  880. if(bookauthor_identifier==1)
  881. {
  882. puts("Going back to menu in 5sec");
  883. Sleep(5000);
  884. }
  885.  
  886. }
  887. void search_linkedlist_book_all(book* head)
  888. {
  889. system("clear");
  890. book* p=head;
  891.  
  892. while(p != NULL)
  893. {
  894. printf("%d|%s|%s|%s|%lld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  895. p = p->next;
  896. }
  897.  
  898. puts("Going back to menu in 5sec");
  899. Sleep(5000);
  900. }
  901.  
  902.  
  903. book* create_linkedlist_book(int n)
  904. {
  905.  
  906. book* head=NULL;
  907. book* temp=NULL;
  908. book* p = NULL;
  909.  
  910.  
  911. int i;
  912.  
  913.  
  914. for(i=0;i<n;i++)
  915. {
  916. temp =(book*)malloc(sizeof(book));
  917. temp->next=NULL;
  918.  
  919.  
  920.  
  921. if(head==NULL)
  922. {
  923. head=temp;
  924. }
  925. else
  926. {
  927. p=head;
  928. while(p->next != NULL)
  929. p=p->next;
  930. p->next = temp;
  931. }
  932. }
  933. return head;
  934. }
  935.  
  936. void download_linkedlist_book(book* head)
  937. {
  938. book* p=head;
  939.  
  940. FILE *f=fopen("book.txt","r");
  941.  
  942. while(p !=NULL)
  943. {
  944. fscanf(f,"%d|%[^|]|%[^|]|%[^|]|%lld|%[^|]|%s\n",&(p->book_num),p->book_name,p->publisher,p->author,&(p->ISBN),p->book_address,p->Y_N);
  945. p = p->next;
  946. }
  947. fclose(f);
  948. }
  949.  
  950. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  951.  
  952. void sort_linkedlist_book(book* head)
  953. {
  954. book *i,*j;
  955. int temp1;
  956. long long temp5;
  957. char temp2[100],temp3[100],temp4[100],temp6[100],temp7[2];
  958.  
  959. for(i=head;i->next!=NULL;i=i->next)
  960. {
  961. for(j=i->next; j!=NULL; j=j->next)
  962. {
  963. if(i->ISBN > j->ISBN)
  964. {
  965. temp1 = i->book_num; temp5 = i->ISBN;
  966. strcpy(temp2,i->book_name); strcpy(temp3,i->publisher); strcpy(temp4,i->author); strcpy(temp6,i->book_address); strcpy(temp7,i->Y_N);
  967.  
  968. i->book_num = j->book_num; i->ISBN = j->ISBN;
  969. strcpy(i->book_name,j->book_name); strcpy(i->publisher,j->publisher);strcpy(i->author,j->author);strcpy(i->book_address,j->book_address);strcpy(i->Y_N,j->Y_N);
  970.  
  971. j->book_num = temp1; j->ISBN = temp5;
  972. strcpy(j->book_name,temp2); strcpy(j->publisher,temp3); strcpy(j->author,temp4); strcpy(j->book_address,temp6); strcpy(j->Y_N,temp7);
  973. }
  974. }
  975. }
  976. }
  977.  
  978.  
  979.  
  980. void upload_linkedlist_book(book* head)
  981. {
  982. book* p=head;
  983. FILE *f=fopen("book.txt","w");
  984.  
  985. while(p !=NULL)
  986. {
  987. fprintf(f,"%d|%s|%s|%s|%ld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  988. p = p->next;
  989. }
  990. fclose(f);
  991. }
  992.  
  993. void Register_linkedlist_book(int booknum,book* head)
  994. {
  995. book* p=head;
  996. FILE *f=fopen("book.txt","a");
  997. char temp1[100],temp2[100],temp3[100],temp5[100];
  998. long long temp4;
  999.  
  1000. puts("Book name:");
  1001. getchar();
  1002. scanf("%[^\n]",temp1);
  1003. puts("Publisher:");
  1004. getchar();
  1005. scanf("%[^\n]",temp2);
  1006. puts("Author:");
  1007. getchar();
  1008. scanf("%[^\n]",temp3);
  1009. puts("ISBN:");
  1010. scanf("%lld",&temp4);
  1011. puts("Book adrress:");
  1012. getchar();
  1013. scanf("%[^\n]",temp5);
  1014.  
  1015. fprintf(f,"%d|%s|%s|%s|%ld|%s|Y\n",booknum+1,temp1,temp2,temp3,temp4,temp5);
  1016.  
  1017.  
  1018. fclose(f);
  1019. }
  1020. int Readbookname_linkedlist_book(book* head,int length)
  1021. {
  1022. book* p=head;
  1023.  
  1024. for(int i=0;i<length;i++)
  1025. {
  1026. if(i==length-1)
  1027. {
  1028. return p->book_num;
  1029. }
  1030. p=p->next;
  1031. }
  1032. return 0;
  1033.  
  1034. }
  1035.  
  1036. void delete_linkedlist_book(book* head)
  1037. {
  1038. int menuselect;
  1039. long long tempISBN;
  1040. char tempbookname[100];
  1041. int repeat_value=1;
  1042.  
  1043. book* p=head;
  1044. puts("1.Delete by book name");
  1045. puts("2.Delete by ISBN");
  1046. scanf("%d",&menuselect);
  1047.  
  1048. if(menuselect==1)
  1049. {
  1050. puts("Enter book name");
  1051. while(getchar() != '\n');
  1052. scanf("%[^\n]",tempbookname);
  1053. while(1)
  1054. {
  1055. if(strcmp(p->book_name,tempbookname)==0)
  1056. {
  1057. if(strcmp(p->Y_N,"N")==0)
  1058. {
  1059. puts("YOU CAN`T BORROW THIS BOOK");
  1060. puts("Turn back to menu in 5sec..");
  1061. Sleep(5000);
  1062. break;
  1063. }
  1064. printf("%d|%s|%s|%s|%ld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  1065. puts("Delete in 5sec");
  1066. Sleep(5000);
  1067.  
  1068. p=head;
  1069. FILE* f=fopen("book.txt","w");
  1070. int i=1;
  1071. while(p!=NULL)
  1072. {
  1073.  
  1074. if(i!=repeat_value)
  1075. fprintf(f,"%d|%s|%s|%s|%ld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  1076.  
  1077. ++i;
  1078. p=p->next;
  1079. }
  1080. fclose(f);
  1081. break;
  1082. }
  1083. repeat_value++;
  1084. p=p->next;
  1085. }
  1086.  
  1087.  
  1088. }
  1089.  
  1090.  
  1091.  
  1092. if(menuselect==2)
  1093. {
  1094. puts("Enter ISBN");
  1095. scanf("%lld",&tempISBN);
  1096. while(1)
  1097. {
  1098. if(p->ISBN==tempISBN)
  1099. {
  1100. if(strcmp(p->Y_N,"N")==0)
  1101. {
  1102. puts("YOU CAN`T BORROW THIS BOOK");
  1103. puts("Turn back to menu in 5sec..");
  1104. Sleep(5000);
  1105. break;
  1106. }
  1107. printf("%d|%s|%s|%s|%ld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  1108. puts("Delete in 5sec");
  1109. Sleep(5000);
  1110.  
  1111. p=head;
  1112. FILE* f=fopen("book.txt","w");
  1113. int i=1;
  1114. while(p!=NULL)
  1115. {
  1116.  
  1117. if(i!=repeat_value)
  1118. fprintf(f,"%d|%s|%s|%s|%ld|%s|%s\n",p->book_num,p->book_name,p->publisher,p->author,p->ISBN,p->book_address,p->Y_N);
  1119.  
  1120. ++i;
  1121. p=p->next;
  1122. }
  1123. fclose(f);
  1124. break;
  1125. }
  1126. repeat_value++;
  1127. p=p->next;
  1128. }
  1129.  
  1130.  
  1131. }
  1132. }
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140. client* create_NOINPUT_linkedlist_client(int n)
  1141. {
  1142.  
  1143. client* head=NULL;
  1144. client* temp=NULL;
  1145. client* p = NULL;
  1146. int i;
  1147.  
  1148. for(i=0;i<n;i++)
  1149. {
  1150. temp =(client*)malloc(sizeof(client));
  1151. temp->next=NULL;
  1152.  
  1153. if(head==NULL)
  1154. {
  1155. head=temp;
  1156. }
  1157. else
  1158. {
  1159. p=head;
  1160. while(p->next != NULL)
  1161. p=p->next;
  1162. p->next = temp;
  1163. }
  1164. }
  1165. return head;
  1166. }
  1167.  
  1168.  
  1169. client* search_by_clientname(client* head)
  1170. {
  1171. system("clear");
  1172. char temp_clientname[100];
  1173. puts("Enter client name");
  1174. while(getchar()!='\n');
  1175. scanf("%[^\n]",temp_clientname);
  1176.  
  1177. client* p=head;
  1178. while(p!=NULL)
  1179. {
  1180. if(strcmp(p->NAME,temp_clientname)==0)
  1181. {
  1182. printf("%d|%s|%s|%s\n",p->ID,p->NAME,p->ADDRESS,p->PNUM);
  1183. }
  1184. p=p->next;
  1185. }
  1186. puts("Going back to previous menu in 5sec...");
  1187. Sleep(5000);
  1188. }
  1189.  
  1190.  
  1191. client* search_by_ID(client* head)
  1192. {
  1193. system("clear");
  1194. int temp_clientID;
  1195. puts("Enter client ID");
  1196. scanf("%d",&temp_clientID);
  1197.  
  1198. client* p=head;
  1199. while(p!=NULL)
  1200. {
  1201. if(p->ID==temp_clientID)
  1202. {
  1203. printf("%d|%s|%s|%s\n",p->ID,p->NAME,p->ADDRESS,p->PNUM);
  1204. }
  1205. p=p->next;
  1206. }
  1207. puts("Going back to previous menu in 5sec...");
  1208. Sleep(5000);
  1209. }
  1210.  
  1211. client* Print_all_client(client* head)
  1212. {
  1213. system("clear");
  1214. puts(">>PRINT ALL<<");
  1215.  
  1216. client* p=head;
  1217. while(p!=NULL)
  1218. {
  1219. printf("%d|%s|%s|%s\n",p->ID,p->NAME,p->ADDRESS,p->PNUM);
  1220. p=p->next;
  1221. }
  1222. puts("Going back to previous menu in 5sec...");
  1223. Sleep(5000);
  1224.  
  1225. }
Add Comment
Please, Sign In to add comment