Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #define DEBUG printf("여기까진 괜찮앙\n")
  7. typedef struct _Book{
  8. int book_id; //도서번호
  9. char *book_name; //도서명
  10. char *purblisher; //출판사
  11. char *writer; //저자명
  12. long isbn; //ISBN
  13. char *local; //소장처
  14. char book_rent; //대여가능 여부
  15. struct _Book *next; //자기참조
  16. }Book;
  17.  
  18. typedef struct _Client{
  19. int std_id; //학번
  20. char *password; //비밀번호
  21. char *std_name; //학생 이름
  22. char *addr; //주소
  23. char *ph_num; //핸드폰 번호
  24. struct _Client *next;
  25. } Client;
  26.  
  27. typedef struct _Borrow{
  28. int std_id; //학번
  29. int bk_id; //도서번호
  30. time_t rent_date; //빌린 날짜
  31. time_t return_date; //반납 날짜
  32. struct _Borrow *next;
  33. } Borrow;
  34.  
  35. /*-------------영민,민영-------------*/
  36. typedef struct _client {
  37. int std_id; //학번
  38. char password[300]; //비밀번호
  39. char std_name[300]; //이름
  40. char addr[300]; //주소
  41. char ph_num[300]; //연락처
  42. struct _client* next;
  43. }client;
  44. /*-------------영민,민영-------------*/
  45.  
  46. /*----------------용준-----------------*/
  47. typedef struct book {
  48.  
  49. char bnum[8];//책번호
  50. char bname[100];//책이름
  51. char pname[100];//출판사이름
  52. char writer[100];//저자명
  53. char ISBN[15];//ISBN번호
  54. char own[100];//소장처
  55. char YN;//Y or N 대여가능여부
  56. struct book *next;
  57. } book;//book.txt파일에서 책 정보 읽어오는 자기참조구조체선언
  58. /*-----------------용준----------------*/
  59.  
  60.  
  61. void login();
  62. int admin_login(); //로그인 함수
  63. void book_manage(int num, Book *cur, Client *cl_cur, Borrow *br_cur);
  64. char *get_string(char * str, int start);
  65. Book *create_node(Book *data);
  66. void insert_node(Book **cur, Book *new_node);
  67. void add_node(Book **cur, Book *new_node, Book *next_node);
  68. void delete_node(Book **cur, Book *del_node);
  69. Book *book_regis(Book **cur);
  70. Borrow *create_br_node(Borrow *data);
  71. void insert_br_node(Borrow **cur, Borrow *new_node);
  72. void delete_br_node(Borrow **cur, Borrow *del_node);
  73. Client *create_cl_node(Client *data);
  74. void insert_cl_node(Client **cur, Client *new_node);
  75. time_t make_time (time_t date, int *year, int *month, int *day);
  76. void mul_time(time_t date, int *year, int *month, int *day);
  77.  
  78. /*-------------영민-------------*/
  79. void client_add();
  80. void register_member(); // 회원 등록
  81. void member_menu(); // 회원 메뉴
  82. void modify_member(); // 회원 정보 수정
  83. void delete_member(); // 회원 탈퇴
  84.  
  85. client *client_head;
  86. client *client_tail;
  87.  
  88. char id_login[300]; // 로그인할때 쓸 학번
  89. char password_login[50]; // 로그인할때 쓸 비밀번호
  90. /*-------------영민-------------*/
  91.  
  92. /*-------------민영-------------*/
  93. void search_name(FILE *); //이름 검색 함수
  94. void all_client(FILE *); //전체검색
  95. void client_list(); //전채검색
  96. void search_id_num(FILE *); //학번검색
  97.  
  98. /*-------------민영-------------*/
  99.  
  100. /*-------------용준-------------*/
  101. typedef book *LINK;//struct book *형을 LINK정의.
  102. void findbname(FILE *);//책이름검색함수
  103. void findpname(FILE *, char *);//출판사명검색함수
  104. void findISBN(FILE *);//ISBN검색함수
  105. void findwriter(FILE *, char *);//작가명검색함수
  106. void findall(FILE *);//전체검색함수
  107. void search();//회원 로그인 후 도서검색 눌렀을때 실행
  108. /*-------------용준-------------*/
  109.  
  110. FILE *fp,*bfp,*cfp,*dfp,*ifp;
  111.  
  112. int main (void) {
  113.  
  114. /*-------------영민-------------*/
  115. client_head=(client *)malloc(sizeof(client));
  116. client_tail=(client *)malloc(sizeof(client));
  117. client_add();
  118. /*-------------영민-------------*/
  119.  
  120. bfp = fopen("./borrow.txt","a+w");
  121. if(bfp == NULL) printf("파일없음\n");
  122. Borrow *br_p = (Borrow*)malloc(sizeof(Borrow));
  123. Borrow *br_head = (Borrow*)malloc(sizeof(Borrow));
  124. Borrow *br_cur = br_head;
  125. br_head->next = NULL;
  126. br_head->std_id=0;
  127.  
  128. char *br_info = (char *)malloc(1024);
  129. int br_curNum=0;
  130.  
  131. while(fgets(br_info,1024,bfp) != NULL) { //구조체에 데이터 파싱
  132. br_curNum=0;
  133. br_p->std_id = atoi(get_string(br_info,br_curNum));
  134. br_curNum += 9;
  135. br_p->bk_id = atoi(get_string(br_info,br_curNum));
  136. br_curNum += strlen(get_string(br_info,br_curNum))+1;
  137. br_p->rent_date = atoi(get_string(br_info,br_curNum));
  138. br_curNum += strlen(get_string(br_info,br_curNum))+1;
  139. br_p->return_date = atoi(get_string(br_info,br_curNum));
  140.  
  141. insert_br_node(&br_cur,create_br_node(br_p));
  142. }
  143. br_cur = br_head;
  144.  
  145. cfp = fopen("./client.txt","a+w");
  146. if(cfp == NULL) printf("파일없음\n");
  147. Client *cl_p = (Client*)malloc(sizeof(Client));
  148. Client *cl_head = (Client*)malloc(sizeof(Client));
  149. Client *cl_cur = cl_head;
  150. cl_head->next = NULL;
  151. cl_head->std_id = 0;
  152.  
  153. char *cl_info = (char *)malloc(1024);
  154. int cl_curNum = 0;
  155.  
  156. while(fgets(cl_info,1024,cfp) != NULL) {
  157. cl_curNum = 0;
  158. cl_p->std_id = atoi(get_string(cl_info,cl_curNum));
  159. cl_curNum += 9;
  160. cl_p->password = get_string(cl_info,cl_curNum);
  161. cl_curNum += strlen(cl_p->password)+1;
  162. cl_p->std_name = get_string(cl_info,cl_curNum);
  163. cl_curNum += strlen(cl_p->std_name)+1;
  164. cl_p->addr = get_string(cl_info,cl_curNum);
  165. cl_curNum += strlen(cl_p->addr)+1;
  166. cl_p->ph_num = get_string(cl_info,cl_curNum);
  167. cl_curNum += strlen(cl_p->ph_num)+1;
  168.  
  169. insert_cl_node(&cl_cur,create_cl_node(cl_p));
  170. }
  171. cl_cur = cl_head->next;
  172.  
  173.  
  174. /* 링크드리스트 */
  175.  
  176. fp = fopen("./book.txt","a+w");
  177. if(fp == NULL) printf("파일 없음\n");
  178. Book *book_p=(Book*)malloc(sizeof(Book));
  179.  
  180. Book *head = (Book *)malloc(sizeof(Book));
  181. Book *cur = head;
  182. head->next = NULL;
  183. head -> book_id = 0;
  184.  
  185. char *info = (char *)malloc(1024);
  186. int curNum=0;
  187. while(fgets(info, 1024, fp) != NULL) { //구조체에 데이터 파싱
  188. curNum=0;
  189. book_p->book_id = atoi(get_string(info, curNum));
  190. curNum += sizeof(book_p->book_id)*2;
  191. book_p->book_name=get_string(info,curNum);
  192. curNum += strlen(book_p->book_name)+1;
  193. book_p->purblisher=get_string(info, curNum);
  194. curNum += strlen(book_p->purblisher)+1;
  195. book_p->writer=get_string(info, curNum);
  196. curNum += strlen(book_p->writer)+1;
  197. book_p->isbn = atol(get_string(info, curNum));
  198. curNum += sizeof(book_p->isbn)+6;
  199. book_p->local=get_string(info, curNum);
  200. curNum += strlen(book_p->local)+1;
  201. char *rent=get_string(info, curNum);
  202. book_p->book_rent=rent[0];
  203. curNum += 1;
  204.  
  205. insert_node(&cur, create_node(book_p));
  206.  
  207. }
  208.  
  209. cur=head->next;
  210.  
  211.  
  212. /* 메인화면 */
  213. int select;
  214. system("clear");
  215.  
  216. while(1) {
  217. // system("clear");
  218. printf(">>도서관 서비스<<\n");
  219. printf("1. 회원가입\t2.로그인\t3. 프로그램종료\n");
  220. printf("번호를 선택하세요: ");
  221.  
  222. scanf("%d", &select);
  223.  
  224. if(select == 1) {
  225. //회원가입 함수
  226. /*-------------영민-------------*/
  227. register_member();
  228. /*-------------영민-------------*/
  229. } else if(select == 2) {
  230. //로그인함수
  231. // system("clear");
  232. login();
  233. }
  234.  
  235.  
  236.  
  237. else if(select == 3) {
  238. /*-------------영민-------------*/
  239. printf("====================================\n");
  240. printf("프로그램을 종료합니다\n");
  241. exit(1);
  242. /*-------------영민-------------*/
  243. }
  244. }
  245.  
  246. fclose(fp);
  247. fclose(bfp);
  248. fclose(cfp);
  249.  
  250. return 0;
  251. }
  252.  
  253. void login()
  254. {
  255. while (1)
  256. {
  257. printf(">>로그인<<\n");
  258. printf("학번: ");
  259. scanf("%s", id_login);
  260.  
  261. if (!strcmp(id_login, "admin"))
  262. {
  263. printf("비밀번호: ");
  264. scanf("%s", password_login);
  265.  
  266. if (!strcmp(password_login, "lib_admin7"))
  267. {
  268. admin_login(); //관리자용 메뉴로 이동
  269. break;
  270. }
  271.  
  272. else
  273. {
  274. printf("비밀번호가 틀렸습니다. 다시입력하십시오.\n");
  275. id_login[0] = '\0';
  276. password_login[0] = '\0';
  277. continue; //로그인 화면 처음으로 이동
  278. }
  279. }
  280.  
  281. else
  282. {
  283. client* current = (client*)malloc(sizeof(client));
  284. current = client_head;
  285.  
  286. while (current != client_tail)
  287. {
  288. if (current->std_id == atoi(id_login)) //입력한 학번이 존재할 때
  289. {
  290. printf("비밀번호: ");
  291. scanf("%s", password_login);
  292.  
  293. if (!strcmp(current->password, password_login)) //비밀번호가 맞으면 회원용 메뉴로 이동
  294. {
  295. member_menu();
  296. break;
  297. }
  298. else //아니면 반복문 나온후 로그인 화면 처음으로 이동
  299. {
  300. printf("비밀번호가 틀렸습니다. 다시 입력하세요.\n");
  301. password_login[0] = '\0';
  302. break;
  303. }
  304. }
  305. current = current->next;
  306. }
  307.  
  308. if (current == client_tail) //linked_list를 전부 확인해도 입력한 학번이 없을 때
  309. {
  310. printf("존재하지 않는 학번입니다. 다시 입력하세요.\n");
  311. continue; //로그인 화면으로 이동
  312. }
  313.  
  314. if (!strcmp(current->password, password_login)) //회원용 메뉴를 나오면 로그인 화면종료
  315. break; //비밀번호가 다를경우 로그인화면 으로 이동
  316. }
  317. }
  318. }
  319.  
  320. int admin_login() {
  321. system("clear");
  322. Book *cur;
  323. Client *cl_cur;
  324. Borrow *br_cur;
  325.  
  326. int num;
  327.  
  328. printf(">> 관리자 메뉴 <<\n");
  329. printf("1. 도서 등록 2. 도서 삭제\n");
  330. printf("3. 도서 대여 4. 도서 반납\n");
  331. printf("5. 도서 검색 6. 회원 목록\n");
  332. printf("7. 로그아웃 8. 프로그램 종료\n");
  333. printf("번호를 선택하세요 : ");
  334. scanf("%d", &num);
  335.  
  336. if(num == 1 || num == 2 || num == 3 || num == 4 || num == 5)
  337. book_manage(num,cur,cl_cur,br_cur);
  338. else if(num == 6) {
  339. /*------------민영----------*/
  340. client_list();
  341. //회원 목록
  342. } else if (num == 7) {
  343. //로그아웃
  344. return 0;
  345. } else if (num == 8) {
  346. exit(0);
  347. }
  348.  
  349. return 0;
  350. }
  351.  
  352. void book_manage(int num, Book *cur, Client *cl_cur, Borrow *br_cur) {
  353. int del_num=0,rent_num=0;
  354. system("clear");
  355.  
  356. switch(num) {
  357. case 1 : //도서 등록 //isbn순으로 정렬
  358. {
  359. Book *tail, *corr_cur;
  360. Book *bk_head = cur;
  361.  
  362. printf(">>도서 등록<<\n");
  363. tail = book_regis(&cur); //마지막 번호 받아옴
  364. cur = bk_head;
  365. while (cur != NULL) {
  366. if(cur->isbn > tail->isbn){ //기존isbn보다 tail isbn보다 작은거 찾기
  367. corr_cur=cur;
  368. break;
  369. }
  370. cur = cur->next;
  371. }
  372. cur = bk_head; //head값 저장
  373. FILE *fp = fopen("book.txt", "wt");
  374. while(cur != NULL) {
  375. fprintf(fp, "%d|%s|%s|%s|%ld|%s|%c\n",cur->book_id, cur->book_name, cur->purblisher,
  376. cur->writer, cur->isbn, cur->local, cur->book_rent);
  377. if(cur->next == corr_cur) break;
  378. cur = cur->next;
  379. }
  380. fprintf(fp, "%d|%s|%s|%s|%ld|%s|%c\n",tail->book_id, tail->book_name, tail->purblisher,
  381. tail->writer, tail->isbn, tail->local, tail->book_rent);
  382. Book *next_node = cur->next;
  383. add_node(&cur,create_node(tail), next_node);
  384. cur = cur->next;
  385. while(cur != NULL) {
  386. fprintf(fp, "%d|%s|%s|%s|%ld|%s|%c\n",cur->book_id, cur->book_name, cur->purblisher,
  387. cur->writer, cur->isbn, cur->local, cur->book_rent);
  388. cur = cur->next;
  389. }
  390. cur = bk_head;
  391. fclose(fp);
  392. break;
  393. }
  394. case 2 : // 도서 삭제
  395. printf(">>도서 삭제<<\n");
  396. printf("1. 도서명 검색 2. ISBN 검색\n");
  397. printf("검색 번호를 입력하세요 : ");
  398. scanf("%d",&del_num);
  399. Book *head; //head위치 저장포인터
  400. head = cur;
  401. Book *corr_cur=cur; //null이 아님을 피하기위해 초기화
  402. Book *del_node; //지울 노드 전번째 노드위치 포인터
  403. int null_check = 0, del_id = 0; //도서이름이 있는지 확인변수, 삭제할 도서번호
  404. if(del_num == 1) {
  405. char b_name[100]=""; //도서 이름입력변수
  406.  
  407. printf("도서명을 입력하세요 : ");
  408. getchar();
  409. scanf("%[^\n]", b_name);
  410.  
  411. while(cur != NULL) { //찾는 도서이름이 없는지 확인
  412. if(!strcmp(cur->book_name, b_name)) //도서이름이 있으면
  413. null_check ++;
  414. cur=cur->next;
  415. }
  416. if(null_check == 0) corr_cur = NULL; //도서이름이 없으면
  417. cur = head;
  418. if(corr_cur != NULL) { //찾는 도서이름이 있으면
  419. printf("도서 번호 :");
  420. while(cur != NULL) {
  421. if(!strcmp(cur->book_name,b_name)){
  422. printf(" %d(삭제 가능 여부 : %c)",cur->book_id, cur->book_rent);
  423. corr_cur = cur; // 도서위치저장
  424. }
  425. cur=cur->next;
  426. }
  427. printf("\n도서명 : %s\n",corr_cur->book_name);
  428. printf("출판사 : %s\n", corr_cur->purblisher);
  429. printf("저자명 : %s\n", corr_cur->writer);
  430. printf("ISBN : %ld\n", corr_cur->isbn);
  431. printf("소장처 : %s\n", corr_cur->local);
  432. printf("\n삭제할 도서의 번호를 입력하세요 : ");
  433. scanf("%d", &del_id);
  434. cur=head; //cur위치는 다시 처음으로
  435. int check=0,success=0;
  436. while(cur != NULL) {
  437. if(!strcmp(cur->book_name,b_name) && cur->book_id == del_id) {
  438. check++;
  439. corr_cur=cur; //지울노드에 현재커서위치 넘겨주기
  440. if(cur->book_rent=='N') {
  441. printf("이 도서는 삭제할 수 없습니다.\n");
  442. } else if (cur->book_rent=='Y') {
  443. success = 1;
  444. printf("도서를 삭제했습니다.\n");
  445. }
  446. }
  447. if(cur->book_id==(del_id-1)) {
  448. del_node=cur; //지울노드 전노드 위치 넘겨주기
  449. }
  450. cur = cur->next;
  451. }
  452. cur=head; //cur위치 다시 처음으로
  453. FILE *dfp;
  454. if(success==1) {
  455. delete_node(&del_node,corr_cur);
  456. dfp = fopen("./book.txt","wt");
  457. while(cur!=NULL) {
  458. fprintf(dfp, "%d|%s|%s|%s|%ld|%s|%c\n", cur->book_id, cur->book_name, cur->purblisher,
  459. cur->writer, cur->isbn, cur->local, cur->book_rent);
  460. cur=cur->next;
  461. }
  462. } else { //예외 처리
  463. dfp = fopen("./book.txt","r");
  464. }
  465. fclose(dfp);
  466. if(check == 0)
  467. printf("도서 번호가 잘못되었습니다.\n");
  468. } else if (corr_cur == NULL) {
  469. printf("찾으시는 도서이름이 없습니다.\n");
  470. }
  471. } else if (del_num == 2) {
  472. long b_isbn;
  473. printf("ISBN을 입력하세요 : ");
  474. scanf("%ld", &b_isbn);
  475.  
  476. while(cur != NULL) {
  477. if(cur->isbn == b_isbn) //찾는 도서 isbn이 있으면
  478. null_check ++;
  479. cur=cur->next;
  480. }
  481. if(null_check == 0) corr_cur = NULL; //도서이름이 없으면
  482. cur = head;
  483. if(corr_cur != NULL) { //있을때
  484. printf("도서 번호 :");
  485. while(cur != NULL) {
  486. if(cur->isbn == b_isbn) {
  487. printf(" %d(삭제 가능 여부: %c)", cur->book_id, cur->book_rent);
  488. corr_cur = cur; //도서위치저장
  489. }
  490. cur=cur->next;
  491. }
  492. printf("\n도서명 : %s\n",corr_cur->book_name);
  493. printf("출판사 : %s\n", corr_cur->purblisher);
  494. printf("저자명 : %s\n", corr_cur->writer);
  495. printf("ISBN : %ld\n", corr_cur->isbn);
  496. printf("소장처 : %s\n", corr_cur->local);
  497. printf("\n삭제할 도서의 번호를 입력하세요 : ");
  498. scanf("%d", &del_id);
  499. cur=head; //cur위치는 다시 처음으로
  500. int check=0,success=0;
  501. while(cur != NULL) {
  502. if(cur->isbn == b_isbn && cur->book_id == del_id) {
  503. check++;
  504. corr_cur=cur; //지울노드에 현재커서위치 넘겨주기
  505. if(cur->book_rent=='N') {
  506. printf("이 도서는 삭제할 수 없습니다.\n");
  507. } else if (cur->book_rent=='Y') {
  508. success = 1;
  509. printf("도서를 삭제했습니다.\n");
  510. }
  511. }
  512. if(cur->book_id==(del_id-1)) {
  513. del_node=cur; //지울노드 전노드 위치 넘겨주기
  514. }
  515. cur = cur->next;
  516. }
  517. cur=head; //cur위치 다시 처음으로
  518. FILE *dfp;
  519. if(success==1) {
  520. delete_node(&del_node,corr_cur);
  521. dfp = fopen("./book.txt","wt");
  522. while(cur!=NULL) {
  523. fprintf(dfp, "%d|%s|%s|%s|%ld|%s|%c\n", cur->book_id, cur->book_name, cur->purblisher,
  524. cur->writer, cur->isbn, cur->local, cur->book_rent);
  525. cur=cur->next;
  526. }
  527. } else { //예외 처리
  528. dfp = fopen("./book.txt","r");
  529. }
  530. fclose(dfp);
  531. if(check == 0)
  532. printf("도서 번호가 잘못되었습니다.\n");
  533. } else if(corr_cur == NULL) { //없을때
  534. printf("찾으시는 도서ISBN이 없습니다.\n");
  535. }
  536. } else { //1,2번 아닌거 입력했을때
  537. printf("번호를 잘못 입력하셨습니다.\n");
  538. }
  539. break;
  540. case 3 :
  541. {
  542. //도서 대여
  543. printf(">>도서 대여<<\n");
  544. printf("1. 도서명 검색 2. ISBN 검색\n");
  545. printf("\n검색 번호를 입력하세요 : ");
  546. scanf("%d", &rent_num);
  547. Borrow *br_head=br_cur;
  548. Book *bk_head=cur;
  549. Client *cl_head=cl_cur;
  550. Book *cor_cur=cur; //null이 아님을 피하기 위해 초기화
  551. int n_check=0;
  552. if(rent_num == 1){
  553. char b_name[100]="",rent='\0';
  554. int s_id=0,b_id=0;
  555.  
  556. getchar();
  557. printf("도서명을 입력하세요 : ");
  558. scanf("%[^\n]", b_name);
  559.  
  560. while(cur != NULL) {
  561. if(!strcmp(cur->book_name, b_name)) //도서이름이 있으면
  562. n_check ++;
  563. cur=cur->next;
  564. }
  565. if(n_check == 0) cor_cur = NULL; //도서이름이 없으면
  566. cur = bk_head;
  567. if(cor_cur != NULL) { //찾는 도서이름이 있으면
  568. printf("도서 번호 :");
  569. while(cur != NULL) {
  570. if(!strcmp(cur->book_name,b_name)){
  571. printf(" %d(대여 가능 여부 : %c)",cur->book_id, cur->book_rent);
  572. cor_cur = cur; // 도서위치저장
  573. }
  574. cur=cur->next;
  575. }
  576. printf("\n도서명 : %s\n",cor_cur->book_name);
  577. printf("출판사 : %s\n", cor_cur->purblisher);
  578. printf("저자명 : %s\n", cor_cur->writer);
  579. printf("ISBN : %ld\n", cor_cur->isbn);
  580. printf("소장처 : %s\n", cor_cur->local);
  581. printf("\n학번을 입력하세요 : ");
  582. scanf("%d", &s_id);
  583. cur=bk_head;
  584. int id_check=0,id_suc=0;
  585. while(cl_cur != NULL) {
  586. if(s_id == cl_cur->std_id) //같으면
  587. id_check = 1;
  588. cl_cur=cl_cur->next;
  589. }
  590. cl_cur = cl_head;//처음으로
  591. if(id_check == 0) {
  592. printf("학번이 잘못되었습니다.\n");
  593. break;
  594. }
  595. printf("도서번호를 입력하세요 : ");
  596. scanf("%d", &b_id);
  597. while(cur != NULL) {
  598. if(b_id == cur->book_id) {
  599. id_suc=1;
  600. cor_cur = cur; //현재위치 잡아주기
  601. }
  602. cur=cur->next;
  603. }
  604. cur = bk_head;
  605. printf("이 도서를 대여합니까? : ");
  606. getchar();
  607. scanf("%c", &rent);
  608.  
  609. FILE *br_fp;
  610. struct tm *t;
  611. time_t timer;
  612. char *weekday[] = {"일요일", "월요일", "화요일", "수요일",
  613. "목요일", "금요일", "토요일"};
  614. char *a_date=(char*)malloc(100);
  615. char *b_date=(char*)malloc(100);
  616. time(&timer);
  617. t = localtime(&timer);
  618. mktime(t);
  619. if(id_suc==1 && rent == 'Y' && cor_cur->book_rent == 'Y') {
  620. printf("도서가 대여 되었습니다.\n");
  621. cor_cur->book_rent = 'N';
  622. br_fp = fopen("./borrow.txt","a+w");
  623. sprintf(a_date, "%d%02d%02d",t->tm_year+1900, t->tm_mon+1, t->tm_mday);
  624. timer += 60*60*24*30;
  625. t = localtime(&timer);
  626. mktime(t);
  627. if(!strcmp(weekday[t->tm_wday],"일요일")){
  628. timer += 60*60*24;
  629. t=localtime(&timer);
  630. mktime(t);
  631. }
  632. sprintf(b_date, "%d%02d%02d",t->tm_year+1900, t->tm_mon+1, t->tm_mday);
  633. fprintf(br_fp,"%d|%d|%s|%s\n", s_id, b_id, a_date, b_date);
  634. fclose(br_fp);
  635. bfp=fopen("./book.txt","wt");
  636. while(cur != NULL) {
  637. if(cur->book_id==cor_cur->book_id){
  638. //부분수정
  639. fprintf(bfp, "%d|%s|%s|%s|%ld|%s|%c\n", cor_cur->book_id, cor_cur->book_name,
  640. cor_cur->purblisher,cor_cur->writer, cor_cur->isbn,
  641. cor_cur->local, cor_cur->book_rent);
  642. }
  643. else {
  644. fprintf(bfp, "%d|%s|%s|%s|%ld|%s|%c\n", cur->book_id, cur->book_name, cur->purblisher,
  645. cur->writer, cur->isbn, cur->local, cur->book_rent);
  646. }
  647. cur=cur->next;
  648. }
  649. fclose(bfp);
  650. } else if(id_suc==1 && rent == 'Y' && cor_cur->book_rent == 'N') {
  651. printf("도서 대여를 실패했습니다.\n");
  652. } else if (rent == 'N') {
  653. printf("도서 대여를 취소합니다. \n");
  654. }
  655. free(a_date);
  656. free(b_date);
  657.  
  658. } else if(cor_cur == NULL) {
  659. printf("찾으시는 도서이름이 없습니다.\n");
  660. }
  661.  
  662. } else if (rent_num == 2) { //isbn검색
  663. long b_isbn;
  664. char rent='\0';
  665. int s_id=0,b_id=0;
  666. printf("ISBN을 입력하세요 : ");
  667. scanf("%ld", &b_isbn);
  668.  
  669. while(cur != NULL) {
  670. if(cur->isbn == b_isbn) //찾는 도서 isbn이 있으면
  671. n_check ++;
  672. cur=cur->next;
  673. }
  674. if(n_check == 0) cor_cur = NULL; //도서 isbn이 없으면
  675.  
  676. cur = bk_head;
  677. if(cor_cur != NULL) { //찾는 도서isbn이 있으면
  678. printf("도서 번호 :");
  679. while(cur != NULL) {
  680. if(cur->isbn == b_isbn) {
  681. printf(" %d(대여 가능 여부 : %c)",cur->book_id, cur->book_rent);
  682. cor_cur = cur; // 도서위치저장
  683. }
  684. cur=cur->next;
  685. }
  686. printf("\n도서명 : %s\n",cor_cur->book_name);
  687. printf("출판사 : %s\n", cor_cur->purblisher);
  688. printf("저자명 : %s\n", cor_cur->writer);
  689. printf("ISBN : %ld\n", cor_cur->isbn);
  690. printf("소장처 : %s\n", cor_cur->local);
  691. printf("\n학번을 입력하세요 : ");
  692. scanf("%d", &s_id);
  693. cur=bk_head;
  694. int id_check=0,id_suc=0;
  695. while(cl_cur != NULL) {
  696. if(s_id == cl_cur->std_id) //같으면
  697. id_check = 1;
  698. cl_cur=cl_cur->next;
  699. }
  700. cl_cur = cl_head;//처음으로
  701. if(id_check == 0) {
  702. printf("학번이 잘못되었습니다.\n");
  703. break;
  704. }
  705. printf("도서번호를 입력하세요 : ");
  706. scanf("%d", &b_id);
  707. while(cur != NULL) {
  708. if(b_id == cur->book_id) {
  709. id_suc=1;
  710. cor_cur = cur; //현재위치 잡아주기
  711. }
  712. cur=cur->next;
  713. }
  714. cur = bk_head;
  715. printf("이 도서를 대여합니까? : ");
  716. getchar();
  717. scanf("%c", &rent);
  718. FILE *br_fp;
  719. struct tm *t;
  720. time_t timer;
  721. char *weekday[] = {"일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"};
  722. char *a_date=(char*)malloc(100);
  723. char *b_date=(char*)malloc(100);
  724. time(&timer); //시간받아오는거
  725. t = localtime(&timer); //시간 나눠주는거
  726. mktime(t); //요일
  727. if(id_suc==1 && rent == 'Y' && cor_cur->book_rent == 'Y') {
  728. printf("도서가 대여 되었습니다.\n");
  729. cor_cur->book_rent = 'N';
  730. br_fp = fopen("./borrow.txt","a+w");
  731. sprintf(a_date, "%d%02d%02d",t->tm_year+1900, t->tm_mon+1, t->tm_mday);
  732. timer += 60*60*24*30;
  733. t = localtime(&timer);
  734. mktime(t);
  735. if(!strcmp(weekday[t->tm_wday],"일요일")){
  736. timer += 60*60*24;
  737. t=localtime(&timer);
  738. mktime(t);
  739. }
  740. sprintf(b_date, "%d%02d%02d",t->tm_year+1900, t->tm_mon+1, t->tm_mday);
  741. fprintf(br_fp,"%d|%d|%s|%s\n", s_id, b_id, a_date, b_date);
  742. fclose(br_fp);
  743. bfp=fopen("./book.txt","wt");
  744. while(cur != NULL) {
  745. if(cur->book_id==cor_cur->book_id){
  746. fprintf(bfp, "%d|%s|%s|%s|%ld|%s|%c\n", cor_cur->book_id, cor_cur->book_name,
  747. cor_cur->purblisher,cor_cur->writer, cor_cur->isbn,
  748. cor_cur->local, cor_cur->book_rent);
  749. }
  750. else {
  751. fprintf(bfp, "%d|%s|%s|%s|%ld|%s|%c\n", cur->book_id, cur->book_name, cur->purblisher,
  752. cur->writer, cur->isbn, cur->local, cur->book_rent);
  753. }
  754. cur=cur->next;
  755. }
  756. fclose(bfp);
  757. } else if(id_suc==1 && rent == 'Y' && cor_cur->book_rent == 'N') {
  758. printf("도서 대여를 실패했습니다.\n");
  759. } else if (rent == 'N') {
  760. printf("도서 대여를 취소합니다. \n");
  761. }
  762. free(a_date);
  763. free(b_date);
  764.  
  765. } else if(cor_cur == NULL) {
  766. printf("찾으시는 도서가 없습니다.\n");
  767. }
  768. } else {
  769. printf("번호를 잘못 입력하셨습니다.\n");
  770. }
  771. break;
  772. }
  773. case 4 :
  774. {
  775. //도서 반납
  776. int s_id=0, bk_id=0, success=0;
  777. int year, month, day;
  778. Borrow *br_head=br_cur;
  779. Book *bk_head=cur;
  780. Client *cl_head=cl_cur;
  781. Borrow *del_node,*corr_cur;
  782. char rent='\0';
  783. printf("학번을 입력하세요 : ");
  784. scanf("%d", &s_id);
  785. struct tm* timeinfo;
  786. char *weekday[] = {"일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"};
  787.  
  788. printf(">>회원의 대여 목록<<\n");
  789. br_cur = br_head->next;
  790. while(br_cur != NULL) {
  791. if(br_cur->std_id == s_id) {
  792. bk_id = br_cur->bk_id;
  793. printf("도서번호 : %d\n", bk_id);
  794. while(cur != NULL) {
  795. if(cur->book_id == bk_id)
  796. printf("도서명 : %s\n", cur->book_name);
  797. cur=cur->next;
  798. }
  799. cur = bk_head;
  800.  
  801. mul_time(br_cur->rent_date, &year, &month, &day);
  802. time_t baseTime = make_time(br_cur->rent_date, &year, &month, &day);
  803.  
  804. timeinfo = localtime(&baseTime);
  805. timeinfo->tm_year = year - 1900;
  806. timeinfo->tm_mon = month - 1;
  807. timeinfo->tm_mday = day;
  808. mktime(timeinfo);
  809.  
  810. mul_time(br_cur->return_date, &year, &month, &day);
  811. baseTime = make_time(br_cur->return_date, &year, &month, &day);
  812.  
  813. timeinfo = localtime(&baseTime);
  814. timeinfo->tm_year = year - 1900;
  815. timeinfo->tm_mon = month - 1;
  816. timeinfo->tm_mday = day;
  817. mktime(timeinfo);
  818. printf("대여 일자 : %ld%s\n",br_cur->rent_date,weekday[timeinfo->tm_wday]);
  819. printf("반납 일자 : %ld%s\n\n",br_cur->return_date,weekday[timeinfo->tm_wday]);
  820. }
  821. br_cur=br_cur->next;
  822. }
  823. printf("반납할 도서번호를 입력하세요 : ");
  824. scanf("%d",&bk_id);
  825. printf("\n도서 반납처리를 할까요? : ");
  826. getchar();
  827. scanf("%c",&rent);
  828. corr_cur = br_head;
  829. br_cur=br_head->next;
  830. if(rent == 'Y') {
  831. while (br_cur != NULL) {
  832. if(br_cur->bk_id == bk_id) {
  833. break;
  834. }
  835. corr_cur = br_cur; //지울 노드 찾기
  836. br_cur = br_cur->next;
  837. }
  838. delete_br_node(&corr_cur, br_cur);
  839. } else {
  840. printf("반납처리를 취소합니다. \n");
  841. }
  842. br_cur = br_head->next;
  843. if(rent == 'Y') {
  844. FILE *fp = fopen("./borrow.txt", "wt");
  845. while(br_cur != NULL) { //borrow파일 수정
  846. fprintf(fp, "%d|%d|%ld|%ld\n",br_cur->std_id,br_cur->bk_id,br_cur->rent_date,br_cur->return_date);
  847. br_cur = br_cur->next;
  848. }
  849. br_cur = br_head->next;
  850.  
  851. FILE *bfp = fopen("./book.txt", "wt");
  852. while(cur != NULL) { //book파일 수정
  853. if(cur->book_id==bk_id){
  854. cur->book_rent = rent;
  855. fprintf(bfp, "%d|%s|%s|%s|%ld|%s|%c\n", cur->book_id, cur->book_name,
  856. cur->purblisher,cur->writer, cur->isbn,
  857. cur->local, cur->book_rent);
  858. } else {
  859. fprintf(bfp, "%d|%s|%s|%s|%ld|%s|%c\n", cur->book_id, cur->book_name, cur->purblisher,
  860. cur->writer, cur->isbn, cur->local, cur->book_rent);
  861. }
  862. cur=cur->next;
  863. }
  864. cur=bk_head;
  865.  
  866. fclose(fp);
  867. fclose(bfp);
  868. }
  869.  
  870. break;
  871. }
  872. case 5 :
  873. //도서 검색
  874. break;
  875. }
  876.  
  877. }
  878. /*-----------------------민영-------------------------*/
  879. void client_list() {
  880. FILE *dfp = NULL; //client 파일을 여는 파일 포인터 선언
  881. dfp = fopen("client.txt", "r");
  882. if (dfp == NULL) {
  883. return;
  884. }
  885. int choice;
  886. char name[10]; //입력받을 이름
  887.  
  888.  
  889. printf(">>검색 결과<<\n");
  890. printf("1.이름 검색\t 2.학번 검색\n3.전체 검색\t 4.이전 메뉴\n");
  891. printf("번호를 입력하세요\n");
  892. scanf("%d", &choice);
  893. switch (choice) {
  894. case 1:
  895. search_name(dfp);
  896. printf("\n\n");
  897. client_list();
  898. break;
  899. case 2:
  900. search_id_num(dfp);
  901. printf("\n\n");
  902. client_list();
  903. break;
  904. case 3: {
  905. all_client(dfp);
  906. printf("\n\n");
  907. client_list();
  908. }
  909. break;
  910. case 4:
  911. fclose(dfp);
  912.  
  913. break;
  914. default:
  915. printf("1~4사이 숫자를 입력하세요");
  916. break;
  917.  
  918. }
  919. fclose(dfp);
  920. return;
  921. }
  922.  
  923. void search_name(FILE *dfp) //이름 검색 함수
  924. {
  925. char input_name[20];
  926. char buf[10];
  927. client *head = NULL;
  928. client *p = NULL;
  929. client *q = (client *)malloc(sizeof(client));
  930.  
  931. printf("이름을 입력하세요:");
  932. scanf("%s", input_name);
  933. while (1) {
  934. if (fscanf(dfp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]\n", buf, q->password, q->std_name, q->addr, q->ph_num) != 5)
  935. {
  936. printf("검색 결과 없음");
  937. break;
  938. }
  939. q->std_id = atoi(buf);
  940. if (strcmp(input_name, q->std_name) != 0)
  941. {
  942.  
  943. continue;
  944. }
  945. else
  946. {
  947. printf("학번:%d\n이름:%s\n주소:%s\n전화번호:%s\n", q->std_id, q->std_name, q->addr, q->ph_num);
  948. break;
  949. }
  950. }
  951. }
  952.  
  953. void search_id_num(FILE *dfp) //학번검색함수
  954.  
  955. {
  956.  
  957. int input_id;
  958. char buf[10];
  959.  
  960. client *head = NULL;
  961. client *q = NULL;
  962. client *p = NULL;
  963. q = (client *)malloc(sizeof(client));
  964. printf("학번을 입력하세요:");
  965. scanf("%d", &input_id);
  966. while (1) {
  967.  
  968. if (fscanf(dfp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]\n", buf, q->password, q->std_name, q->addr, q->ph_num) != 5)
  969. {
  970. printf("검색결과가 없습니다.");
  971. break;
  972. }
  973. q->std_id = atoi(buf);
  974.  
  975. if (input_id == q->std_id) {
  976.  
  977. printf("\n학번:%d\n이름:%s\n주소:%s\n전화번호:%s", q->std_id, q->std_name, q->addr, q->ph_num);
  978.  
  979. break;
  980. }
  981. }
  982. }
  983.  
  984.  
  985.  
  986. void all_client(FILE *dfp) //전체 검색함수
  987. {
  988. int count = 0;
  989. client *head = NULL;
  990. client *p = NULL;
  991. client *q = NULL;
  992. char buf[10];
  993. while (1) {
  994. q = malloc(sizeof(client));
  995. q->next = NULL;
  996. if (head == NULL)
  997. {
  998. head = q;
  999. if (fscanf(dfp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]\n", buf, q->password, q->std_name, q->addr, q->ph_num) == 5)
  1000. {
  1001. q->std_id = atoi(buf);
  1002.  
  1003. printf("학번:%d\n", q->std_id);
  1004. printf("이름:%s\n", q->std_name);
  1005. printf("주소:%s\n", q->addr);
  1006. printf("전화번호:%s\n\n", q->ph_num);
  1007. }
  1008. }
  1009. else {
  1010. p = head;
  1011. while (p->next != NULL) {
  1012. p = p->next;
  1013. }
  1014. p->next = q;
  1015. if (fscanf(dfp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]\n", buf, q->password, q->std_name, q->addr, q->ph_num) == 5)
  1016. {
  1017. q->std_id = atoi(buf);
  1018. printf("학번:%d\n", q->std_id);
  1019. printf("이름:%s\n", q->std_name);
  1020. printf("주소:%s\n", q->addr);
  1021. printf("전화번호:%s\n\n", q->ph_num);
  1022.  
  1023. }
  1024. else {
  1025. free(q);
  1026. return;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. /*----------------------민영--------------------*/
  1032.  
  1033.  
  1034. time_t make_time (time_t date, int *year, int *month, int *day) {
  1035. char* weekday[] = {"일요일", "월요일", "화요일", "수요일",
  1036. "목요일", "금요일", "토요일"};
  1037.  
  1038. struct tm t = {0};
  1039. t.tm_year = *year - 1900;
  1040. t.tm_mon = *month - 1;
  1041. t.tm_mday = *day;
  1042.  
  1043. return mktime(&t);
  1044. }
  1045. void mul_time(time_t date, int *year, int *month, int *day) {
  1046. *year= date / 10000 ;
  1047. *month = (date - ((*year) * 10000)) / 100;
  1048. *day = date % 100 ;
  1049. }
  1050.  
  1051. Client *create_cl_node(Client *data) {
  1052. Client *new_node = (Client*)malloc(sizeof(Client));
  1053. memcpy(new_node, data, sizeof(Client));
  1054. new_node->next = NULL;
  1055. return new_node;
  1056. }
  1057.  
  1058. void insert_cl_node(Client **cur, Client *new_node) {
  1059. (*cur)->next = new_node;
  1060. *cur = new_node;
  1061. }
  1062.  
  1063. Borrow *create_br_node(Borrow *data) {
  1064. Borrow *new_node = (Borrow*)malloc(sizeof(Borrow));
  1065. memcpy(new_node, data, sizeof(Borrow));
  1066. new_node->next = NULL;
  1067. return new_node;
  1068. }
  1069.  
  1070. void insert_br_node(Borrow **cur, Borrow *new_node) {
  1071. (*cur)->next = new_node;
  1072. *cur = new_node;
  1073. }
  1074.  
  1075. void delete_br_node(Borrow **cur, Borrow *del_node) {
  1076. (*cur)->next = del_node->next;
  1077. free(del_node);
  1078. }
  1079.  
  1080. Book *create_node(Book *data){
  1081. Book *new_node = (Book*)malloc(sizeof(Book));
  1082. memcpy(new_node, data, sizeof(Book));
  1083. new_node->next = NULL;
  1084. return new_node;
  1085. }
  1086.  
  1087. void insert_node(Book **cur, Book *new_node) {
  1088. (*cur)->next = new_node;
  1089. *cur = new_node;
  1090. }
  1091.  
  1092. void add_node(Book **cur, Book *new_node, Book *next_node) {
  1093. (*cur)->next = new_node;
  1094. *cur = new_node;
  1095. (*cur) -> next = next_node;
  1096. }
  1097.  
  1098. void delete_node(Book **cur, Book *del_node) {
  1099. (*cur)->next = del_node->next;
  1100. free(del_node);
  1101. }
  1102.  
  1103. char *get_string(char * str, int start){
  1104. int i = 0;
  1105. char * temp = (char*)calloc(1024, sizeof(char));
  1106. while(str[start] != '|' && str[start] != '\n' && str[start] != '\0'){
  1107. temp[i] = str[start];
  1108. i++;
  1109. start++;
  1110. }
  1111. return temp;
  1112. }
  1113.  
  1114. Book *book_regis(Book **cur) { //책 등록
  1115. char input[100]="";
  1116. char *name, *purb, *writer, *local, answer;
  1117. int last_id=0;
  1118. long isbn;
  1119.  
  1120.  
  1121. printf("도서명 : ");
  1122. scanf("%s", input);
  1123. name = (char *)malloc(strlen(input));
  1124. strcpy(name,input);
  1125.  
  1126. printf("출판사 : ");
  1127. scanf("%s", input);
  1128. purb = (char *)malloc(strlen(input));
  1129. strcpy(purb,input);
  1130.  
  1131. printf("저자명 : ");
  1132. scanf("%s", input);
  1133. writer = (char *)malloc(strlen(input));
  1134. strcpy(writer,input);
  1135.  
  1136. printf("ISBN : ");
  1137. scanf("%ld", &isbn);
  1138.  
  1139. printf("소장처 : ");
  1140. scanf("%s", input);
  1141. local = (char *)malloc(strlen(input));
  1142. strcpy(local,input);
  1143.  
  1144. while ((*cur) != NULL) {
  1145. if((*cur)->book_id > last_id) {
  1146. last_id = (*cur)->book_id;
  1147. }
  1148. *cur = (*cur) -> next;
  1149. }
  1150. last_id++;
  1151.  
  1152. getchar();
  1153. printf("\n자동 입력 사항\n\n대여가능 여부 : Y\n도서 번호 : %d\n\n저장하시겠습니까? ",last_id);
  1154. scanf("%c", &answer);
  1155.  
  1156. if(answer == 'Y') {
  1157. Book *book_p = (Book *)malloc(sizeof(Book));
  1158.  
  1159. book_p->book_id = last_id;
  1160.  
  1161. book_p->book_name = (char *)malloc(sizeof(name));
  1162. strcpy(book_p->book_name, name);
  1163.  
  1164. book_p->purblisher = (char *)malloc(sizeof(purb));
  1165. strcpy(book_p->purblisher,purb);
  1166.  
  1167. book_p->writer = (char *)malloc(sizeof(writer));
  1168. strcpy(book_p->writer, writer);
  1169.  
  1170. book_p->isbn = isbn;
  1171.  
  1172. book_p->local = (char *)malloc(sizeof(local));
  1173. strcpy(book_p->local, local);
  1174.  
  1175. book_p->book_rent = 'Y';
  1176.  
  1177.  
  1178. return book_p;
  1179. }
  1180. return NULL;
  1181. }
  1182. /*-------------용준-------------*/
  1183. void search() {//도서검색실행
  1184. FILE *ifp = NULL;
  1185. ifp = fopen("book.txt", "r");
  1186. printf(">> 도서 검색<<\n1.도서명 검색 2. 출판사 검색\n3.ISBN 검색 4. 저자명 검색\n5.전체 검색 6. 이전 메뉴\n\n");
  1187. printf("번호를 선택하세요:");
  1188. int c;//도서검색에서 선택할 번호입력.
  1189. scanf("%d", &c);
  1190. while (getchar() != '\n');//scanf이후 버퍼에서 엔터('\n')지우기
  1191. if (c == 1)
  1192. {
  1193. findbname(ifp);
  1194. fclose(ifp);
  1195. printf("\n\n");
  1196. search();
  1197. }
  1198. else
  1199. if (c == 2)
  1200. {
  1201. char s[100];//출판사명 입력할 배열
  1202. printf("출판사명을 입력하세요:");
  1203. scanf("%[^\n]", s);
  1204. while (getchar() != '\n');
  1205. findpname(ifp, s);
  1206. fclose(ifp);
  1207. printf("\n\n");
  1208. search();
  1209. }
  1210. else
  1211. if (c == 3)
  1212. {
  1213. findISBN(ifp);
  1214. fclose(ifp);
  1215. printf("\n\n");
  1216. search();
  1217. }
  1218. else
  1219. if (c == 4)
  1220. {
  1221. char s[100];//작가명 입력할 배열 생성.
  1222. printf("작가명을 입력하세요:");
  1223. scanf("%[^\n]", s);
  1224. while (getchar() != '\n');
  1225. findwriter(ifp, s);//인자로 파일포인터와 문자열 전달.
  1226. fclose(ifp);
  1227. printf("\n\n");
  1228. search();
  1229. }
  1230. else
  1231. if (c == 5)
  1232. {
  1233. findall(ifp);
  1234. fclose(ifp);
  1235. printf("\n\n");
  1236. search();
  1237. }
  1238. else if (c == 6)
  1239. {
  1240. fclose(ifp);
  1241. return;
  1242. }
  1243. else
  1244. {
  1245. printf("잘못된 선택입니다. 1~6중에서 선택해주세요.\n");
  1246. fclose(ifp);
  1247. search();
  1248. }
  1249. fclose(ifp);
  1250. return;
  1251. }
  1252.  
  1253. void findbname(FILE *ifp) {
  1254. char s[100];//도서명입력
  1255. LINK head = NULL;
  1256. LINK p = NULL;
  1257. LINK q = NULL;
  1258. LINK r = NULL;
  1259. int n1 = 0;//대여가능여부 Y의 수
  1260. int n2 = 0;//대여가능여부 N의 수
  1261. printf("도서명을 입력하세요:");
  1262. scanf("%[^\n]", s);
  1263. while (getchar() != '\n');
  1264. while (1) {
  1265. q = (LINK)malloc(sizeof(book));
  1266. q->next = NULL;
  1267. if (head == NULL)
  1268. {
  1269. head = q;
  1270. head->next = NULL;
  1271. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", head->bnum, head->bname, head->pname, head->writer, head->ISBN, head->own, &head->YN) != 7)
  1272. {
  1273. printf("검색오류입니다.\n");
  1274. free(q);
  1275. break;
  1276. }
  1277. if (!strcmp(s, head->bname))
  1278. {
  1279. if (head->YN == 'Y')
  1280. n1++;
  1281. else
  1282. n2++;
  1283. r = malloc(sizeof(book));
  1284. r->next = NULL;
  1285. while (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1286. if (!strcmp(r->ISBN, head->ISBN))//같은 도서 존재하면 YN(대여가능여부)검사 후 대여가능(Y)이면 n1에 1더하고 대여불가능(N)이면 n2에 1더함.
  1287. {
  1288. if (r->YN == 'Y')
  1289. n1++;//복사
  1290. else
  1291. n2++;
  1292. }
  1293. free(r);
  1294. if (n1>0)
  1295. head->YN = 'Y';
  1296. printf("\n\n>> 검색 결과 <<\n");
  1297. printf("도서명:%s\n", s);
  1298. printf("출판사:%s\n", head->pname);
  1299. printf("저자명:%s\n", head->writer);
  1300. printf("ISBN :%s\n", head->ISBN);
  1301. printf("소장처:%s\n", head->own);
  1302. printf("대여가능 여부:%c(%d/%d)\n", head->YN, n2, n1 + n2);
  1303. free(q);
  1304. break;
  1305. }
  1306. }
  1307. else
  1308. {
  1309. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) != 7)
  1310. {
  1311. printf("도서명 검색 실패입니다.\n");
  1312. free(q);
  1313. break;
  1314. }
  1315. q->next = NULL;
  1316. p = head;
  1317. while (p->next != NULL)
  1318. p = p->next;//p포인터 이동
  1319. p->next = q;
  1320. if (!strcmp(s, q->bname))//복사
  1321. {
  1322. if (q->YN == 'Y')
  1323. n1++;
  1324. else
  1325. n2++;
  1326. r = malloc(sizeof(book));
  1327. r->next = NULL;
  1328. while (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1329. if (!strcmp(r->ISBN, q->ISBN))
  1330. {
  1331. if (r->YN == 'Y')
  1332. n1++;
  1333. else
  1334. n2++;
  1335. }
  1336. free(r);
  1337. if (n1>0)
  1338. q->YN = 'Y';
  1339. printf("\n\n>> 검색 결과 <<\n");
  1340. printf("도서명:%s\n", q->bname);
  1341. printf("출판사:%s\n", q->pname);
  1342. printf("저자명:%s\n", q->writer);
  1343. printf("ISBN :%s\n", q->ISBN);
  1344. printf("소장처:%s\n", q->own);
  1345. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);
  1346. free(q);
  1347. break;
  1348. }
  1349. }
  1350. }
  1351. return;
  1352. }
  1353.  
  1354. void findpname(FILE *ifp, char *s) {//출판사검색
  1355. FILE *ifp2 = NULL;
  1356. ifp2 = fopen("book.txt", "r");
  1357. LINK head = NULL;
  1358. LINK p = NULL;
  1359. LINK q = NULL;
  1360. LINK r = NULL;
  1361. int n1 = 0;
  1362. int n2 = 0;
  1363. int n3 = 0;//같은책이 몇권인지 셈.
  1364. while (1) {
  1365. q = malloc(sizeof(book));
  1366. q->next = NULL;
  1367. if (head == NULL)
  1368. {
  1369. head = q;
  1370. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) == 7)
  1371. {
  1372. if (!strcmp(s, q->pname))
  1373. {
  1374. r = malloc(sizeof(book));
  1375. r->next = NULL;
  1376. while (fscanf(ifp2, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1377. {
  1378. if (!strcmp(r->ISBN, q->ISBN))
  1379. {
  1380. if (r->YN == 'Y')
  1381. n1++;
  1382. else
  1383. n2++;
  1384. }
  1385. n3 = n1 + n2 - 1;
  1386. if (n3 >= 0)
  1387. if ((!strcmp(r->pname, q->pname)) && (strcmp(r->ISBN, q->ISBN)))
  1388. {
  1389. for (int k = 0; n3>k; k++)//같은책수만큼 파일지시자 이동
  1390. fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN);
  1391. fclose(ifp2);
  1392. findpname(ifp, q->pname);
  1393. }
  1394. }
  1395. free(r);
  1396. if (n1>0)
  1397. q->YN = 'Y';//복사
  1398. printf("\n\n>> 검색 결과 <<\n");
  1399. printf("도서명:%s\n", q->bname);
  1400. printf("출판사:%s\n", q->pname);
  1401. printf("저자명:%s\n", q->writer);
  1402. printf("ISBN :%s\n", q->ISBN);
  1403. printf("소장처:%s\n", q->own);
  1404. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);
  1405. free(q);
  1406. break;
  1407. }
  1408. }
  1409. else
  1410. {
  1411. free(q);
  1412. return;
  1413. }
  1414. }
  1415. else//head!=NULL일떄
  1416. {
  1417. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) == 7)//복사
  1418. {
  1419. q->next = NULL;
  1420. p = head;
  1421. while (p->next != NULL)
  1422. p = p->next;
  1423. p->next = q;
  1424. if (!strcmp(s, q->pname)) {
  1425. r = malloc(sizeof(book));
  1426. r->next = NULL;
  1427. while (fscanf(ifp2, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1428. {
  1429. if (!strcmp(r->ISBN, q->ISBN))
  1430. {
  1431. if (r->YN == 'Y')
  1432. n1++;
  1433. else
  1434. n2++;
  1435. }
  1436.  
  1437. n3 = n1 + n2 - 1;
  1438. if (n3 >= 0)
  1439. if ((!strcmp(r->pname, q->pname)) && (strcmp(r->ISBN, q->ISBN)))
  1440. {
  1441. for (int k = 0; n3>k; k++)
  1442. fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN);
  1443. fclose(ifp2);
  1444. findpname(ifp, q->pname);
  1445. }
  1446. }
  1447. free(r);
  1448. if (n1>0)
  1449. q->YN = 'Y';
  1450.  
  1451. printf("\n\n>> 검색 결과 <<\n");
  1452. printf("도서명:%s\n", q->bname);
  1453. printf("출판사:%s\n", q->pname);
  1454. printf("저자명:%s\n", q->writer);
  1455. printf("ISBN :%s\n", q->ISBN);
  1456. printf("소장처:%s\n", q->own);
  1457. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);
  1458. free(q);
  1459. break;
  1460. }
  1461. }
  1462. else
  1463. {
  1464. free(q);
  1465. return;
  1466. }
  1467. }
  1468. }
  1469. fclose(ifp2);
  1470. return;
  1471. }
  1472.  
  1473. void findwriter(FILE *ifp, char *s) {//작가명검색
  1474. FILE *ifp2 = NULL;
  1475. ifp2 = fopen("book.txt", "r");
  1476. LINK head = NULL;
  1477. LINK p = NULL;
  1478. LINK q = NULL;
  1479. LINK r = NULL;
  1480. int n1 = 0;
  1481. int n2 = 0;
  1482. int n3 = 0;//같은책이 몇권인지셈.
  1483. while (1) {
  1484. q = malloc(sizeof(book));
  1485. q->next = NULL;
  1486. if (head == NULL)
  1487. {
  1488. head = q;
  1489. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) == 7)
  1490. {
  1491. if (!strcmp(s, q->writer))
  1492. {
  1493. r = malloc(sizeof(book));//한줄씩 읽으면서 같은 책 찾는 임시 공간
  1494. r->next = NULL;
  1495. while (fscanf(ifp2, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1496. {
  1497. if (!strcmp(r->ISBN, q->ISBN))//ISBN이 같은지(도서가 같은지)검사함
  1498. {
  1499. if (r->YN == 'Y')
  1500. n1++;
  1501. else
  1502. n2++;
  1503. }
  1504. n3 = n1 + n2 - 1;
  1505. if (n3 >= 0)
  1506. if ((!strcmp(r->writer, q->writer)) && (strcmp(r->ISBN, q->ISBN)))
  1507. {
  1508. for (int k = 0; n3>k; k++)
  1509. fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN);
  1510. fclose(ifp2);
  1511. findwriter(ifp, q->writer);
  1512. }
  1513. }
  1514. free(r);
  1515. if (n1>0)
  1516. q->YN = 'Y';
  1517. printf("\n\n>> 검색 결과 <<\n");
  1518. printf("도서명:%s\n", q->bname);
  1519. printf("출판사:%s\n", q->pname);
  1520. printf("저자명:%s\n", q->writer);
  1521. printf("ISBN :%s\n", q->ISBN);
  1522. printf("소장처:%s\n", q->own);
  1523. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);
  1524. free(q);
  1525. break;
  1526. }
  1527. }
  1528. else
  1529. {
  1530. free(q);
  1531. return;
  1532. }
  1533. }
  1534. else//head!=NULL
  1535. {
  1536. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) == 7)
  1537. {
  1538. q->next = NULL;
  1539. p = head;
  1540. while (p->next != NULL)
  1541. p = p->next;//p포인터 노드 끝으로 이동
  1542. p->next = q;
  1543. if (!strcmp(s, q->writer)) {
  1544. r = malloc(sizeof(book));
  1545. r->next = NULL;
  1546. while (fscanf(ifp2, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1547. {
  1548. if (!strcmp(r->ISBN, q->ISBN))//ISBN이 같은지(도서가 같은지)검사함 도서 같으면 YN(대여가능여부)검사 후 대여가능(Y)이면 n1에 1더하고 대여불가능(N)이면 n2에 1더함.
  1549. {//복사
  1550. if (r->YN == 'Y')
  1551. n1++;
  1552. else
  1553. n2++;
  1554. }
  1555. n3 = n1 + n2 - 1;
  1556. if (n3 >= 0)
  1557. if ((!strcmp(r->writer, q->writer)) && (strcmp(r->ISBN, q->ISBN)))
  1558. {
  1559. for (int k = 0; n3>k; k++)
  1560. fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN);
  1561. fclose(ifp2);
  1562. findwriter(ifp, q->writer);
  1563. }
  1564. }
  1565. free(r);
  1566. if (n1>0)
  1567. q->YN = 'Y';
  1568.  
  1569. printf("\n\n>> 검색 결과 <<\n");
  1570. printf("도서명:%s\n", q->bname);
  1571. printf("출판사:%s\n", q->pname);
  1572. printf("저자명:%s\n", q->writer);
  1573. printf("ISBN :%s\n", q->ISBN);
  1574. printf("소장처:%s\n", q->own);
  1575. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);
  1576. free(q);
  1577. break;
  1578. }
  1579. }
  1580. else
  1581. {
  1582. free(q);
  1583. return;
  1584. }
  1585.  
  1586. }
  1587. }
  1588. fclose(ifp2);
  1589. return;
  1590. }//복사
  1591.  
  1592. void findISBN(FILE *ifp) {
  1593. char s[14];//검색할 ISBN
  1594. LINK head = NULL;
  1595. LINK p = NULL;
  1596. LINK q = NULL;
  1597. LINK r = NULL;
  1598. int n1 = 0;
  1599. int n2 = 0;
  1600. printf("ISBN을 입력하세요:");
  1601. scanf("%s", s);
  1602. while (getchar() != '\n');
  1603. while (1) {
  1604. q = malloc(sizeof(book));
  1605. q->next = NULL;
  1606. if (head == NULL)
  1607. {
  1608. head = q;
  1609. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) != 7)
  1610. {
  1611. printf("검색오류입니다.");
  1612. free(q);
  1613. break;
  1614. }
  1615. if (!strcmp(s, q->ISBN))
  1616. {
  1617. if (q->YN == 'Y')
  1618. n1++;
  1619. else
  1620. n2++;
  1621. r = malloc(sizeof(book));
  1622. r->next = NULL;
  1623. while (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)
  1624. if (!strcmp(r->ISBN, q->ISBN)) {//ISBN이 같은지(도서가 같은지)검사함 도서 같으면 YN(대여가능여부)검사 후 대여가능(Y)이면 n1에 1더하고 대여불가능(N)이면 n2에 1더함.
  1625. if (r->YN == 'Y')
  1626. n1++;
  1627. else
  1628. n2++;
  1629. }
  1630. free(r);
  1631. if (n1>0)
  1632. q->YN = 'Y';
  1633.  
  1634. printf("\n\n>> 검색 결과 <<\n");
  1635. printf("도서명:%s\n", q->bname);
  1636. printf("출판사:%s\n", q->pname);
  1637. printf("저자명:%s\n", q->writer);
  1638. printf("ISBN :%s\n", q->ISBN);
  1639. printf("소장처:%s\n", q->own);
  1640. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);
  1641. free(q);
  1642. break;
  1643. }
  1644. }
  1645. else
  1646. {
  1647. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) != 7)
  1648. {
  1649. printf("ISBN검색 실패입니다.");
  1650. free(q);
  1651. break;
  1652. }
  1653. q->next = NULL;
  1654. p = head;
  1655. while (p->next != NULL) {
  1656. p = p->next;
  1657. }
  1658. p->next = q;
  1659. if (!strcmp(s, q->ISBN)) {
  1660. if (q->YN == 'Y')
  1661. n1++;
  1662. else
  1663. n2++;
  1664. r = malloc(sizeof(book));
  1665. r->next = NULL;
  1666. while (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", r->bnum, r->bname, r->pname, r->writer, r->ISBN, r->own, &r->YN) == 7)//복사
  1667. if (!strcmp(r->ISBN, q->ISBN)) {
  1668. if (r->YN == 'Y')
  1669. n1++;
  1670. else
  1671. n2++;
  1672. }
  1673. free(r);
  1674. if (n1>0)
  1675. q->YN = 'Y';
  1676.  
  1677. printf("\n\n>> 검색 결과 <<\n");
  1678. printf("도서명:%s\n", q->bname);
  1679. printf("출판사:%s\n", q->pname);
  1680. printf("저자명:%s\n", q->writer);
  1681. printf("ISBN :%s\n", q->ISBN);
  1682. printf("소장처:%s\n", q->own);
  1683. printf("대여가능 여부:%c(%d/%d)\n", q->YN, n2, n1 + n2);//복사
  1684. free(q);
  1685. break;
  1686. }
  1687. }
  1688. }
  1689. return;
  1690. }
  1691.  
  1692. void findall(FILE *ifp) {//전체검색함수.
  1693. LINK head = NULL;
  1694. LINK p = NULL;
  1695. LINK q = NULL;
  1696. printf("\n\n>> 검색 결과 <<\n");
  1697. while (1) {
  1698. q = malloc(sizeof(book));
  1699. q->next = NULL;
  1700. if (head == NULL) {
  1701. head = q;
  1702. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) == 7)
  1703. {
  1704. printf("도서명:%s\n", q->bname);
  1705. printf("출판사:%s\n", q->pname);
  1706. printf("저자명:%s\n", q->writer);
  1707. printf("ISBN :%s\n", q->ISBN);
  1708. printf("소장처:%s\n", q->own);
  1709. printf("대여가능 여부:%c\n\n", q->YN);
  1710. }
  1711. }
  1712. else
  1713. {
  1714. p = head;
  1715. while (p->next != NULL)
  1716. p = p->next;
  1717. p->next = q;
  1718. if (fscanf(ifp, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%c\n", q->bnum, q->bname, q->pname, q->writer, q->ISBN, q->own, &q->YN) == 7)
  1719. {
  1720. printf("도서명:%s\n", q->bname);
  1721. printf("출판사:%s\n", q->pname);
  1722. printf("저자명:%s\n", q->writer);
  1723. printf("ISBN :%s\n", q->ISBN);
  1724. printf("소장처:%s\n", q->own);
  1725. printf("대여가능 여부:%c\n\n", q->YN);
  1726. }
  1727. else
  1728. {
  1729. free(q);
  1730. return;
  1731. }
  1732. }
  1733. }
  1734. }
  1735.  
  1736. /*------------용준----------------*/
  1737.  
  1738.  
  1739.  
  1740. /*-------------영민-------------*/
  1741.  
  1742. void register_member() // 등록
  1743. {
  1744. int student_number; //학번
  1745. char password[50]; //비밀번호
  1746. char name[20]; //이름
  1747. char address[100]; //주소
  1748. char phone_number[12]; //전화번호
  1749.  
  1750. client* current = (client*)malloc(sizeof(client)); //현재 가리키고 있는 구조체 포인터
  1751. client* current_past = (client*)malloc(sizeof(client));
  1752. current_past = current = client_head;
  1753.  
  1754. printf("학번, 비밀번호, 이름, 주소, 전화번호를 입력하세요.\n");
  1755. printf("학번: ");
  1756. scanf("%d", &student_number);
  1757. getchar();
  1758.  
  1759. //기존링크드에 입력받은 값을 학번순으로 삽입하여 새로운 링크드리스트를 만듦
  1760. while (current != client_tail) //링크드의 모든 값을 비교하기 전까지 반복
  1761. {
  1762. if (current->std_id < student_number) // 다음 링크드로 넘어감
  1763. {
  1764. current_past = current;
  1765. current = current->next;
  1766. }
  1767. else if (current->std_id > student_number) // 링크드 사이에 새로운 링크드 삽입
  1768. {
  1769. printf("비밀번호: ");
  1770. scanf("%s", password);
  1771. getchar();
  1772. printf("이름: ");
  1773. scanf("%[^\n]", name);
  1774. getchar();
  1775. printf("주소: ");
  1776. scanf("%[^\n]", address);
  1777. printf("전화번호: ");
  1778. scanf("%s", phone_number);
  1779. getchar();
  1780.  
  1781. if (current_past == current) //입력받은 학번이 링크드의 가장 첫번째 순서일 경우
  1782. {
  1783. client_head = (client*)malloc(sizeof(client));
  1784. client_head->std_id = student_number;
  1785. strcpy(client_head->password, password);
  1786. strcpy(client_head->std_name, name);
  1787. strcpy(client_head->addr, address);
  1788. strcpy(client_head->ph_num, phone_number);
  1789.  
  1790. client_head->next = (client*)malloc(sizeof(client));
  1791. client_head->next = current; //head의 다음 링크드리스트를 기존의 head로 만듦
  1792. client_tail = current->next = (client*)malloc(sizeof(client)); //다음 링크드리스트를 tail로 설정
  1793. break;
  1794. }
  1795. else
  1796. {
  1797. current_past = current_past->next = (client*)malloc(sizeof(client));
  1798. current_past->std_id = student_number; //새로운 링크드리스트에 입력
  1799. strcpy(current_past->password, password);
  1800. strcpy(current_past->std_name, name);
  1801. strcpy(current_past->addr, address);
  1802. strcpy(current_past->ph_num, phone_number);
  1803.  
  1804. current_past->next = (client*)malloc(sizeof(client));
  1805. current_past->next = current; //새로운 링크드리스트 다음에 이전 링크드리스트 연결하여 삽입
  1806. break;
  1807. }
  1808. }
  1809. else
  1810. {
  1811. printf("이미 가입되어 있습니다.\n");
  1812. break;
  1813. }
  1814. }
  1815. if (current == client_tail) // std_id가 마지막 정렬순서일 경우
  1816. {
  1817. printf("비밀번호: ");
  1818. scanf("%s", current->password);
  1819. getchar();
  1820. printf("이름: ");
  1821. scanf("%[^\n]", current->std_name);
  1822. getchar();
  1823. printf("주소: ");
  1824. scanf("%[^\n]", current->addr);
  1825. printf("전화번호: ");
  1826. scanf("%s", current->ph_num);
  1827. getchar();
  1828.  
  1829. current->std_id = student_number; // 마지막 링크에 입력받은 학번
  1830.  
  1831. client_tail = current->next = (client*)malloc(sizeof(client));
  1832. }
  1833.  
  1834.  
  1835. FILE* fp = fopen("client.txt", "a");
  1836. current = client_head; //링크드리스트의 처음으로 이동
  1837.  
  1838. while (current != client_tail) //링크드리스트의 모든 값을 입력하기 전까지 반복
  1839. {
  1840. fprintf(fp, "%d|", current->std_id);
  1841. fprintf(fp, "%s|", current->password);
  1842. fprintf(fp, "%s|", current->std_name);
  1843. fprintf(fp, "%s|", current->addr);
  1844. fprintf(fp, "%s\n", current->ph_num);
  1845.  
  1846. current = current->next; //while문 탈출
  1847. }
  1848. fclose(fp);
  1849.  
  1850. }
  1851. void member_menu() //회원메뉴
  1852. {
  1853. system("clear");
  1854. int choose;
  1855. while(1){
  1856. printf(">>회원 매뉴<<\n");
  1857. printf("1. 도서 검색\t 2. 내 대여 목록\n");
  1858. printf("3. 개인정보 수정\t 4. 회원 탈퇴\n");
  1859. printf("5. 로그아웃\t 6. 프로그램 종료\n");
  1860.  
  1861. printf("번호를 선택하세요:");
  1862. scanf("%d",&choose);
  1863.  
  1864. if(choose==1){
  1865. search();
  1866. //도서 검색 함수
  1867. }
  1868. if(choose==2){
  1869. // 대여 목록 함수
  1870. }
  1871. if(choose==3){
  1872. modify_member();
  1873. }
  1874. if(choose==4){
  1875. delete_member();
  1876. }
  1877. if(choose==5){
  1878. main();
  1879. }
  1880. if(choose==6){
  1881. exit(1);
  1882. }
  1883.  
  1884. }
  1885. }
  1886.  
  1887. void modify_member() // 수정
  1888. {
  1889. int student_id;
  1890. student_id = atoi(id_login);
  1891. char change_password[300]; // 현재 비밀번호
  1892. DEBUG;
  1893. client * current = (client*)malloc(sizeof(client));
  1894. DEBUG;
  1895. current = client_head;
  1896. DEBUG;
  1897. while (current != client_tail) // 현재 학번과 일치하는 링크탐색
  1898. {
  1899. if (current->std_id == student_id)
  1900. break;
  1901. else
  1902. current = current->next;
  1903. }
  1904.  
  1905. while (1)
  1906. {
  1907. printf("개인정보를 수정하기 위해 현재 비밀번호를 입력하세요.\n비밀먼호 : ");
  1908. scanf("%s", change_password);
  1909.  
  1910.  
  1911. if (!strcmp(current->password, change_password))
  1912. {
  1913. printf("수정할 비밀번호, 주소, 전화번호를 입력하세요.\n");
  1914. printf("비밀번호 : ");
  1915. scanf("%s", current->password);
  1916. getchar();
  1917. printf("주소 : ");
  1918. gets(current->addr);
  1919. printf("전화번호 : ");
  1920. scanf("%s", current->ph_num);
  1921. getchar();
  1922.  
  1923. FILE * fp = fopen("client.txt", "w");
  1924. current = client_head;
  1925.  
  1926. while (current != client_tail)
  1927. {
  1928. fprintf(fp, "%d|", current->std_id);
  1929. fprintf(fp, "%s|", current->password);
  1930. fprintf(fp, "%s|", current->std_name);
  1931. fprintf(fp, "%s|", current->addr);
  1932. fprintf(fp, "%s\n", current->ph_num);
  1933.  
  1934. current = current->next;
  1935. }
  1936.  
  1937. fclose(fp);
  1938.  
  1939. break;
  1940. }
  1941. else
  1942. {
  1943. printf("비밀번호가 틀립니다.\n");
  1944. change_password[0] = '\0';
  1945. }
  1946. }
  1947. }
  1948. void client_add() // txt 에 저장된 값을 링크드리스트에 저장해주는 함수
  1949. {
  1950. FILE* fp = fopen("client.txt", "r");
  1951. client* current= (client*)malloc(sizeof(client));
  1952. current= client_head;
  1953. while (!feof(fp)) //파일에 더이상 읽을 값이 없으면 반복문 종료.
  1954. {
  1955. fscanf(fp, "%d|", &current->std_id);
  1956. fscanf(fp, "%[^|]|", current->password);
  1957. fscanf(fp, "%[^|]|", current->std_name);
  1958. fscanf(fp, "%[^|]|", current->addr);
  1959. fscanf(fp, "%[^\n]\n", current->ph_num);
  1960.  
  1961. current = current->next = (client*)malloc(sizeof(client)); //다음 링크드ㄹ스트로로 이동
  1962. }
  1963. fclose(fp);
  1964. client_tail = current;
  1965. }
  1966.  
  1967. void delete_member() // 탈퇴
  1968. {
  1969. int student_id = 0;
  1970. int search = 0;
  1971. student_id = atoi(id_login);
  1972. char now_password[300];
  1973.  
  1974. client * current = (client*)malloc(sizeof(client));
  1975. client * current_past = (client*)malloc(sizeof(client));
  1976. current_past = current = client_head;
  1977.  
  1978. Borrow * br_cur = (Borrow*)malloc(sizeof(Borrow));
  1979. Borrow * br_head = (Borrow*)malloc(sizeof(Borrow));
  1980. br_cur = br_head; // cur=head;
  1981.  
  1982. while (current != client_tail) // 로그인 학번과 일치하는 학번의 링크드리스트 탐색
  1983. {
  1984. if (current->std_id == student_id)
  1985. break;
  1986. else
  1987. {
  1988. current_past = current;
  1989. current = current->next;
  1990. search++;
  1991. }
  1992. }
  1993.  
  1994. while (1)
  1995. {
  1996. if (br_cur->std_id == student_id) // 대여목록에서 로그인 학번과 일치시 진행
  1997. {
  1998. printf("대여한 책이 남아있어 탈퇴할 수 없습니다.\n\n");
  1999. break;
  2000. }
  2001. else
  2002. br_cur = br_cur->next;
  2003.  
  2004. if (search>0) // 첫번째가 아닌 링크드리스트에서 대여한 책이 없을 경우
  2005. {
  2006. while (1)
  2007. {
  2008. printf("현재 비밀번호를 입력해주세요.\n비밀번호 : ");
  2009. scanf("%s", now_password);
  2010.  
  2011. if (!strcmp(current->password, now_password)) // 비밀번호가 일치할 경우
  2012. {
  2013. current_past->next = current->next;
  2014. free(current);
  2015.  
  2016. FILE* fp = fopen("client.txt", "w");
  2017. current = client_head; //링크드의 처음으로 이동
  2018.  
  2019. while (current != client_tail)
  2020. {
  2021. fprintf(fp, "%d|", current->std_id);
  2022. fprintf(fp, "%s|", current->password);
  2023. fprintf(fp, "%s|", current->std_name);
  2024. fprintf(fp, "%s|", current->addr);
  2025. fprintf(fp, "%s\n", current->ph_num);
  2026.  
  2027. current = current->next;
  2028. }
  2029. fclose(fp);
  2030.  
  2031. printf("탈퇴 되었습니다.\n\n");
  2032. break;
  2033. }
  2034. else // 비밀번호가 틀릴경우
  2035. printf("비밀번호가 틀립니다.\n\n");
  2036. }
  2037. break;
  2038. }
  2039. else if (search == 0) // 링크드리스트의 첫번재 회원이 대여한 책이 없을 경우
  2040. {
  2041. while (1)
  2042. {
  2043. printf("현재 비밀번호를 입력해주세요.\n비밀번호 : ");
  2044. scanf("%s", now_password);
  2045.  
  2046. if (!strcmp(current->password, now_password))
  2047. {
  2048. client_head = current->next; // head를 첫번째의 next로 변경
  2049. free(current);
  2050.  
  2051. FILE* fp = fopen("client.txt", "w");
  2052. current = client_head; //링크드리스트의 처음으로 이동
  2053.  
  2054. while (current != client_tail)
  2055. {
  2056. fprintf(fp, "%d|", current->std_id);
  2057. fprintf(fp, "%s|", current->password);
  2058. fprintf(fp, "%s|", current->std_name);
  2059. fprintf(fp, "%s|", current->addr);
  2060. fprintf(fp, "%s\n", current->ph_num);
  2061. current = current->next;
  2062. }
  2063. fclose(fp);
  2064.  
  2065. printf("탈퇴 되었습니다.\n\n");
  2066. break;
  2067. }
  2068. else
  2069. printf("비밀번호가 틀립니다.\n\n");
  2070. }
  2071. break;
  2072. }
  2073. }
  2074. }
  2075.  
  2076.  
  2077. /*-------------영민-------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement