Advertisement
Guest User

Untitled

a guest
May 25th, 2016
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.97 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include <stdbool.h>
  7. #include <locale.h>
  8. #pragma warning(disable : 4996)
  9.  
  10. static bool parse(char s[], int r)
  11. {
  12. int i;
  13. if (!s)
  14. return false;
  15. for (i = 0; i < r - 1; i++)
  16. {
  17. if (s[i] != '0' && s[i] != '1' &&
  18. s[i] != '2' && s[i] != '3' &&
  19. s[i] != '4' && s[i] != '5' &&
  20. s[i] != '6' && s[i] != '7' &&
  21. s[i] != '8' && s[i] != '9') {
  22. return false;
  23. }
  24. if (s[0] == ' ')
  25. {
  26. return false;
  27. }
  28. }
  29. return true;
  30. }
  31.  
  32. static bool parse1(char s[], int r)
  33. {
  34. int i;
  35. if (!s)
  36. return false;
  37. for (i = 0; i < r - 1; i++)
  38. {
  39. if (s[i] != '0' && s[i] != '1' &&
  40. s[i] != '2' && s[i] != '3' &&
  41. s[i] != '4' && s[i] != '5' &&
  42. s[i] != '6' && s[i] != '7' &&
  43. s[i] != '8' && s[i] != '9' && s[i] != '-') {
  44. return false;
  45. }
  46. if (s[i + 1] == '-')
  47. return false;
  48. if (s[i] == ' ')
  49. {
  50. return false;
  51. }
  52. }
  53. return true;
  54. }
  55. typedef char tName[30];
  56. typedef char tBirthday[30];
  57. typedef char tNumber[30];
  58. typedef char tSex[30];
  59. typedef char tSpecial[30];
  60. typedef char tEducation[30];
  61. typedef char tContact[30];
  62. typedef char tCity[30];
  63. typedef char tEmployment[30];
  64. typedef char tSalary[30];
  65. typedef char tCompany[30];
  66. typedef char tPost[30];
  67. typedef char tStatus[30];
  68. typedef char tAge[30];
  69.  
  70. typedef struct Vacancy
  71. {
  72. struct Vacancy* next, *prev;
  73. tCompany company;
  74. tCity city;
  75. tPost post;
  76. tSpecial special;
  77. tAge age;
  78. tEducation education;
  79. tSex sex;
  80. tSalary salary;
  81. } Vacancy;
  82. typedef struct Bidder
  83. {
  84. struct Bidder* next, *prev;
  85. tName name;
  86. tBirthday birthday;
  87. tContact contact;
  88. tSex sex;
  89. tSpecial special;
  90. tEducation education;
  91. tCity city;
  92. tSalary salary;
  93. } Bidder;
  94. static void menu();
  95. void DelNode(Vacancy** Dnode, int count, int Compare);
  96. void DelNodeBidder(Bidder** Dnode, int count, int Compare);
  97. int CheckDigit();
  98. char* CheckLetter(char* name);
  99. void AddNode(Vacancy** head);
  100. void print(Vacancy *node);
  101. void save(Vacancy* pp, Bidder* pp2);
  102. void load(Vacancy** pp2, Bidder** pp);
  103. void Add(char* company, char* city, char* post, char* special, char* education, char* sex, char* age, char* salary, Vacancy **node);
  104. int Search(char* name, Vacancy* node, int N);
  105. int SearchBidder(char* name, Bidder* node, int N);
  106. static void menuSearchVacancy();
  107. static void menuSearchBidder();
  108. void destroylist(Vacancy** n);
  109. void destroylistBidder(Bidder** n);
  110. void printBidder(Bidder* node);
  111. void AddNodeBidder(Bidder** head);
  112. void AddBidder(char* name, char* birthday, char* contact, char* sex, char* special, char* education, char* city, char* salary, Bidder **node);
  113. int Count(Vacancy* node, int i);
  114. int main()
  115. {
  116. int choise;
  117. int Srch = 0;
  118. char n[256];
  119. setlocale(LC_ALL, "rus");
  120. char name[256];
  121. Vacancy* BufferList = NULL;
  122. Bidder* BufferBidder = NULL;
  123. start:
  124. menu();
  125. if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) <4)
  126. printf("%s", "ok\n");
  127. else
  128. {
  129. (void)puts("ERROR");
  130. destroylist(&BufferList);
  131. destroylistBidder(&BufferBidder);
  132. return 0;
  133. }
  134. switch (atoi(n))
  135. {
  136.  
  137. case 1:
  138. print(BufferList);
  139. puts("Продолжить?");
  140. puts("1. Да ");
  141. puts("2. Нет ");
  142.  
  143. if (CheckDigit() == 1)
  144. goto start;
  145. else
  146. break;
  147. case 2:
  148. AddNode(&BufferList);
  149. goto start;
  150. case 3:
  151. save(BufferList, BufferBidder);
  152. destroylist(&BufferList);
  153. destroylistBidder(&BufferBidder);
  154. goto start;
  155. case 4:
  156. destroylist(&BufferList);
  157. load(&BufferList, &BufferBidder);
  158. goto start;
  159. case 5:
  160. menuSearchVacancy();
  161. choise = CheckDigit();
  162. CheckLetter(name);
  163. Srch = Search(name, BufferList, choise);
  164. if (Srch > 0)
  165. DelNode(&BufferList, Srch - 1, 0);
  166. goto start;
  167. case 6:
  168. printBidder(BufferBidder);
  169. puts("Продолжить?");
  170. puts("1. Да ");
  171. puts("2. нет ");
  172.  
  173. if (CheckDigit() == 1)
  174. goto start;
  175. else
  176. break;
  177.  
  178. case 7:
  179. AddNodeBidder(&BufferBidder);
  180. goto start;
  181. case 8:
  182. menuSearchBidder();
  183. choise = CheckDigit();
  184. CheckLetter(name);
  185. Srch = SearchBidder(name, BufferBidder, choise);
  186. if (Srch > 0)
  187. DelNodeBidder(&BufferBidder, Srch - 1, 0);
  188. goto start;
  189.  
  190. }
  191. destroylist(&BufferList);
  192. destroylistBidder(&BufferBidder);
  193. return 0;
  194. }
  195.  
  196. int Search(char* name, Vacancy* node, int N)
  197. {
  198. int i, k, Check;
  199. int con = 0;
  200. char temp[256];
  201. puts("search");
  202. while (node != NULL)
  203. {
  204. switch (N)
  205. {
  206. case 1:
  207. strcpy(temp, node->company);
  208. break;
  209. case 2:
  210. strcpy(temp, node->city);
  211. break;
  212. case 3:
  213. strcpy(temp, node->post);
  214. break;
  215. case 4:
  216. strcpy(temp, node->special);
  217. break;
  218. case 5:
  219. strcpy(temp, node->education);
  220. break;
  221. case 6:
  222. strcpy(temp, node->sex);
  223. break;
  224. case 7:
  225. strcpy(temp, node->age);
  226. break;
  227. case 8:
  228. strcpy(temp, node->salary);
  229. break;
  230. default:
  231. puts("Ошибка ввода");
  232. }
  233. con++;
  234. k = 0;
  235. Check = 0;
  236. for (i = 0; i < strlen(name);i++)
  237. {
  238. if (name[i] == temp[i])
  239. {
  240. k++;
  241. }
  242. if (k == strlen(name))
  243. if (k == strlen(temp))
  244. {
  245. printf("Название компании - %s\r", node->company);
  246. printf("Город - %s\r", node->city);
  247. printf("Должность - %s\r", node->post);
  248. printf("Специальность - %s\r", node->special);
  249. printf("Образование - %s\r", node->education);
  250. printf("Пол - %s\r", node->sex);
  251. printf("Возраст - %s\r", node->age);
  252. printf("Уровень оплаты - %s\r", node->salary);
  253. puts("\n");
  254. puts("1.Продолжить поиск");
  255. puts("2.Удалить ");
  256. puts("3.Меню ");
  257. Check = CheckDigit();
  258. if (Check == 3)
  259. goto done;
  260. if (Check == 2)
  261. {
  262. return con;
  263.  
  264.  
  265. }
  266. if (Check == 1)
  267. {
  268. }
  269. }
  270.  
  271. }
  272. node = node->next;
  273. }
  274. done:
  275. {
  276. return 0;
  277. }
  278.  
  279. }
  280. int SearchBidder(char* name, Bidder* node, int N)
  281. {
  282. int i, k, Check;
  283. int con = 0;
  284. char temp[256];
  285. puts("search");
  286. while (node != NULL)
  287. {
  288. switch (N)
  289. {
  290. case 1:
  291. strcpy(temp, node->name);
  292. break;
  293. case 2:
  294. strcpy(temp, node->birthday);
  295. break;
  296. case 3:
  297. strcpy(temp, node->contact);
  298. break;
  299. case 4:
  300. strcpy(temp, node->sex);
  301. break;
  302. case 5:
  303. strcpy(temp, node->special);
  304. break;
  305. case 6:
  306. strcpy(temp, node->education);
  307. break;
  308. case 7:
  309. strcpy(temp, node->city);
  310. break;
  311. case 8:
  312. strcpy(temp, node->salary);
  313. break;
  314. default:
  315. puts("Ошибка ввода");
  316. }
  317. con++;
  318. k = 0;
  319. Check = 0;
  320. for (i = 0; i < strlen(name);i++)
  321. {
  322. if (name[i] == temp[i])
  323. {
  324. k++;
  325. }
  326. if (k == strlen(name))
  327. if (k == strlen(temp))
  328. {
  329.  
  330. printf("Имя - %s\r", node->name);
  331. printf("Год рождения - %s\r", node->birthday);
  332. printf("Контакты - %s\r", node->contact);
  333. printf("Пол - %s\r", node->sex);
  334. printf("Специальность - %s\r", node->special);
  335. printf("Образование - %s\r", node->education);
  336. printf("город - %s\r", node->city);
  337. printf("Уровень оплаты - %s\r", node->salary);
  338. puts("\n");
  339. puts("1.Продолжить поиск");
  340. puts("2.Удалить ");
  341. puts("3.Меню ");
  342. Check = CheckDigit();
  343. if (Check == 3)
  344. goto done;
  345. if (Check == 2)
  346. {
  347. return con;
  348.  
  349.  
  350. }
  351. if (Check == 1)
  352. {
  353. }
  354. }
  355.  
  356. }
  357. node = node->next;
  358. }
  359. done:
  360. {
  361. return 0;
  362. }
  363.  
  364. }
  365. void DelNode(Vacancy** Dnode, int count, int Compare)
  366. {
  367. if (Compare == count)
  368. {
  369. Vacancy *tmp = NULL;
  370. tmp = (*Dnode);
  371. (*Dnode) = (*Dnode)->next;
  372. free(tmp);
  373. goto rr;
  374.  
  375. }
  376. else
  377. {
  378.  
  379. DelNode((Vacancy**)(*Dnode), count, Compare + 1);
  380. }
  381. rr: {}
  382. }
  383. void DelNodeBidder(Bidder** Dnode, int count, int Compare)
  384. {
  385. if (Compare == count)
  386. {
  387. Bidder *tmp = NULL;
  388. tmp = (*Dnode);
  389. (*Dnode) = (*Dnode)->next;
  390. free(tmp);
  391. goto rr;
  392.  
  393. }
  394. else
  395. {
  396.  
  397. DelNodeBidder((Bidder**)(*Dnode), count, Compare + 1);
  398. }
  399. rr: {}
  400. }
  401.  
  402.  
  403. void AddBidder(char* name, char* birthday, char* contact, char* sex, char* special, char* education, char* city, char* salary, Bidder **node)
  404. {
  405. Bidder *temp = (Bidder*)malloc(sizeof(Bidder));
  406. memset(temp, 0, sizeof(*temp));
  407. if (!(temp))
  408. {
  409. free(temp);
  410. (void)puts("ERROR MEMORY");
  411. exit(0);
  412. }
  413. strcpy(temp->name, name);
  414. strcpy(temp->birthday, birthday);
  415. strcpy(temp->contact, contact);
  416. strcpy(temp->sex, sex);
  417. strcpy(temp->special, special);
  418. strcpy(temp->education, education);
  419. strcpy(temp->city, city);
  420. strcpy(temp->salary, salary);
  421. temp->next = **&node;
  422. *node = temp;
  423. }
  424.  
  425.  
  426. void Add(char* company, char* city, char* post, char* special, char* education, char* sex, char* age, char* salary, Vacancy **node)
  427. {
  428. Vacancy *temp = (Vacancy *)malloc(sizeof(Vacancy));
  429. memset(temp, 0, sizeof(*temp));
  430. if (!(temp))
  431. {
  432. free(temp);
  433. (void)puts("ERROR MEMORY");
  434. exit(0);
  435. }
  436. strcpy(temp->company, company);
  437. strcpy(temp->city, city);
  438. strcpy(temp->post, post);
  439. strcpy(temp->special, special);
  440. strcpy(temp->education, education);
  441. strcpy(temp->sex, sex);
  442. strcpy(temp->age, age);
  443. strcpy(temp->salary, salary);
  444. temp->next = **&node;
  445. *node = temp;
  446. }
  447.  
  448. void save(Vacancy* pp, Bidder* pp2)
  449. {
  450. FILE *outfile;
  451. FILE *outfile2;
  452. outfile = fopen("acc.dat", "w+");
  453. if (outfile == NULL)
  454. {
  455. fprintf(stderr, "\nError opening acc.dat\n\n");
  456. exit(1);
  457. }
  458. while (pp != NULL)
  459. {
  460. fwrite(pp, sizeof(struct Vacancy), 1, outfile);
  461. pp = pp->next;
  462. }
  463. fclose(outfile);
  464. outfile2 = fopen("acc2.dat", "w+");
  465. while (pp2 != NULL)
  466. {
  467. fwrite(pp2, sizeof(struct Bidder), 1, outfile2);
  468. pp2 = pp2->next;
  469. }
  470. fclose(outfile2);
  471. }
  472.  
  473.  
  474. void load(Vacancy** pp2, Bidder** pp)
  475. {
  476. FILE* infile;
  477. FILE* infile2;
  478. infile = fopen("acc.dat", "a+");
  479. if (infile == NULL)
  480. {
  481. fprintf(stderr, "\nError opening acc.dat\n\n");
  482. exit(1);
  483. }
  484. while (!feof(infile))
  485. {
  486. Vacancy *temp = (Vacancy *)malloc(sizeof(Vacancy));
  487. memset(temp, 0, sizeof(*temp));
  488. fread(temp, sizeof(struct Vacancy), 1, infile);
  489. if (strlen(temp->company) != 0)
  490. Add(temp->company, temp->city, temp->post, temp->special, temp->education, temp->sex, temp->age, temp->salary, pp2);
  491. free(temp);
  492. }
  493. fclose(infile);
  494. infile2 = fopen("acc2.dat", "a+");
  495. if (infile2 == NULL)
  496. {
  497. fprintf(stderr, "\nError opening acc.dat\n\n");
  498. exit(1);
  499. }
  500. while (!feof(infile2))
  501. {
  502. Bidder *temp = (Bidder *)malloc(sizeof(Bidder));
  503. memset(temp, 0, sizeof(*temp));
  504. fread(temp, sizeof(struct Bidder), 1, infile2);
  505. if (strlen(temp->name) != 0)
  506. AddBidder(temp->name, temp->birthday, temp->contact, temp->sex, temp->special, temp->education, temp->city, temp->salary, pp);
  507. free(temp);
  508. }
  509. fclose(infile2);
  510. }
  511. void print(Vacancy *node)
  512. {
  513. puts("Вакансии ");
  514. while (node != NULL)
  515. {
  516. printf("Название компании - %s\r", node->company);
  517. printf("Город - %s\r", node->city);
  518. printf("Должность - %s\r", node->post);
  519. printf("Специальность - %s\r", node->special);
  520. printf("Образование - %s\r", node->education);
  521. printf("Пол - %s\r", node->sex);
  522. printf("Возраст - %s\r", node->age);
  523. printf("Уровень оплаты - %s\r", node->salary);
  524. puts("\n");
  525. node = node->next;
  526. }
  527. puts("\n");
  528. }
  529. void printBidder(Bidder* node)
  530. {
  531. puts("Претенденты ");
  532. while (node != NULL)
  533. {
  534. printf("Имя - %s\r", node->name);
  535. printf("Год рождения - %s\r", node->birthday);
  536. printf("Контакты - %s\r", node->contact);
  537. printf("Пол - %s\r", node->sex);
  538. printf("Специальность - %s\r", node->special);
  539. printf("Образование - %s\r", node->education);
  540. printf("город - %s\r", node->city);
  541. printf("Уровень оплаты - %s\r", node->salary);
  542. puts("\n");
  543. node = node->next;
  544. }
  545. puts("\n");
  546. }
  547. int Count(Vacancy* node, int i)
  548. {
  549. puts("count ");
  550. while (node != NULL)
  551. {
  552. i++;
  553. node = (Vacancy*)node->next;
  554. }
  555. return i;
  556. }
  557. void AddNode(Vacancy** head)
  558. {
  559. int i;
  560. char n[256];
  561. char entry1[256];
  562. char entry2[256];
  563. char entry3[256];
  564. char entry4[256];
  565. char entry5[256];
  566. char entry6[256];
  567. char entry7[256];
  568. char entry8[256];
  569. puts("HOW MUCH?");
  570. if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) < 4)
  571. printf("%s", "\n");
  572. else
  573. {
  574. (void)puts("ERROR");
  575. exit(1);
  576. }
  577. if (atoi(n) != 0)
  578. for (i = 0; i < atoi(n);i++)
  579. {
  580. puts("Введите Название компании");
  581. if (fgets(entry1, 15, stdin) != NULL)
  582. {
  583. puts("Введите Город");
  584. if (fgets(entry2, 15, stdin) != NULL)
  585. {
  586. puts("Введите Должность");
  587. if (fgets(entry3, 15, stdin) != NULL)
  588. {
  589. puts("Введите Специальность");
  590. if (fgets(entry4, 15, stdin) != NULL)
  591. {
  592. puts("Введите Образование");
  593. if (fgets(entry5, 15, stdin) != NULL)
  594. {
  595. puts("Введите Пол");
  596. if (fgets(entry6, 15, stdin) != NULL)
  597. {
  598. puts("Введите Возраст");
  599. if (fgets(entry7, 15, stdin) != NULL)
  600. {
  601. puts("Введите Уровень оплаты");
  602. if (fgets(entry8, 15, stdin) != NULL)
  603. {
  604. Add(entry1, entry2, entry3, entry4, entry5, entry6, entry7, entry8, head);
  605. }
  606. else
  607. {
  608. (void)puts("ERROR");
  609. destroylist(head);
  610. }
  611. }
  612. else
  613. {
  614. destroylist(head);
  615. }
  616. }
  617. else
  618. {
  619. destroylist(head);
  620. }
  621. }
  622. else
  623. {
  624. destroylist(head);
  625. }
  626. }
  627. else
  628. {
  629. destroylist(head);
  630. }
  631. }
  632. else
  633. {
  634. destroylist(head);
  635. }
  636. }
  637. else
  638. {
  639. destroylist(head);
  640. }
  641. }
  642. else
  643. {
  644. destroylist(head);
  645. }
  646. }
  647. }
  648.  
  649. void AddNodeBidder(Bidder** head)
  650. {
  651.  
  652. int i;
  653. char n[256];
  654. char entry1[256];
  655. char entry2[256];
  656. char entry3[256];
  657. char entry4[256];
  658. char entry5[256];
  659. char entry6[256];
  660. char entry7[256];
  661. char entry8[256];
  662. puts("HOW MUCH?");
  663. if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) <4)
  664. printf("%s", "\n");
  665. else
  666. {
  667. (void)puts("ERROR");
  668. exit(1);
  669. }
  670. if (atoi(n) != 0)
  671. for (i = 0; i < atoi(n);i++)
  672. {
  673. puts("Введите Имя ");
  674. if (fgets(entry1, 15, stdin) != NULL)
  675. {
  676. puts("Введите Год рождения");
  677. if (fgets(entry2, 15, stdin) != NULL)
  678. {
  679. puts("Введите Контакты");
  680. if (fgets(entry3, 15, stdin) != NULL)
  681. {
  682. puts("Введите Пол ");
  683. if (fgets(entry4, 15, stdin) != NULL)
  684. {
  685. puts("Введите Специальность ");
  686. if (fgets(entry5, 15, stdin) != NULL)
  687. {
  688. puts("Введите Образование");
  689. if (fgets(entry6, 15, stdin) != NULL)
  690. {
  691. puts("Введите город ");
  692. if (fgets(entry7, 15, stdin) != NULL)
  693. {
  694. puts("Введите Уровень оплаты");
  695. if (fgets(entry8, 15, stdin) != NULL)
  696. {
  697. AddBidder(entry1, entry2, entry3, entry4, entry5, entry6, entry7, entry8, head);
  698. }
  699. else
  700. {
  701. (void)puts("ERROR");
  702. destroylistBidder(head);
  703. }
  704. }
  705. else
  706. {
  707. destroylistBidder(head);
  708. }
  709. }
  710. else
  711. {
  712. destroylistBidder(head);
  713. }
  714. }
  715. else
  716. {
  717. destroylistBidder(head);
  718. }
  719. }
  720. else
  721. {
  722. destroylistBidder(head);
  723. }
  724. }
  725. else
  726. {
  727. destroylistBidder(head);
  728. }
  729. }
  730. else
  731. {
  732. destroylistBidder(head);
  733. }
  734. }
  735. else
  736. {
  737. destroylistBidder(head);
  738. }
  739. }
  740. }
  741. static void menu()
  742. {
  743. (void)puts("\n********************************************************\n");
  744. (void)puts(" 1. Просмотр списка Вакансий \n");
  745. (void)puts(" 2. Добавить в список Вакансий \n");
  746. (void)puts(" 3. Сохранить в файл \n");
  747. (void)puts(" 4. Загрузить из файла \n");
  748. (void)puts(" 5. Поиск по вакансиям \n");
  749. (void)puts(" 6. Просмотр списка Претендентов \n");
  750. (void)puts(" 7. Добавить в список Претендентов \n");
  751. (void)puts(" 8. Поиск по претендентам \n");
  752. (void)puts(" 9. Exit \n");
  753. (void)puts("**********************************************************\n");
  754. }
  755. static void menuSearchBidder()
  756. {
  757.  
  758. (void)puts("\n********************************************************\n");
  759. (void)puts(" 1. Поиск по имени \n");
  760. (void)puts(" 2. Поиск по году рождения \n");
  761. (void)puts(" 3. Поиск по контактам \n");
  762. (void)puts(" 4. Поиск по полу \n");
  763. (void)puts(" 5. Поиск по Специальности \n");
  764. (void)puts(" 6. Поиск по Образованию \n");
  765. (void)puts(" 7. Поиск по городу \n");
  766. (void)puts(" 8. Поиск по Уровеню оплаты \n");
  767. (void)puts(" 9. return. \n");
  768. (void)puts("**********************************************************\n");
  769. }
  770. static void menuSearchVacancy()
  771. {
  772. (void)puts("\n********************************************************\n");
  773. (void)puts(" 1. Поиск по названию компании \n");
  774. (void)puts(" 2. Поиск по городу \n");
  775. (void)puts(" 3. Поиск по должности \n");
  776. (void)puts(" 4. Поиск по специальности \n");
  777. (void)puts(" 5. Поиск по образованию \n");
  778. (void)puts(" 6. Поиск по полу \n");
  779. (void)puts(" 7. Поиск по возрасту \n");
  780. (void)puts(" 8. Поиск по зарплате в $ \n");
  781. (void)puts(" 9. return. \n");
  782. (void)puts("**********************************************************\n");
  783. }
  784. int CheckDigit()
  785. {
  786. char n[256];
  787. if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) <4)
  788. printf("%s", "ok\n");
  789. else
  790. {
  791. (void)puts("ERROR");
  792. return 0;
  793. }
  794. return atoi(n);
  795.  
  796. }
  797. char* CheckLetter(char* name)
  798. {
  799. char n[256];
  800. if (fgets(n, 24, stdin) != NULL && strlen(n) <40)
  801. printf("%s", "ok\n");
  802. else
  803. {
  804. (void)puts("ERROR");
  805. return 0;
  806. }
  807. strcpy(name, n);
  808. return (name);
  809. }
  810. void destroylist(Vacancy** n)
  811. {
  812. if (!*n) return;
  813. destroylist(&((*n)->next));
  814. free(*n);
  815. *n = NULL;
  816. }
  817. void destroylistBidder(Bidder** n)
  818. {
  819. if (!*n) return;
  820. destroylistBidder(&((*n)->next));
  821. free(*n);
  822. *n = NULL;
  823. }
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830. /* razmer
  831. setlocale(LC_ALL, "rus");
  832.  
  833. fseek(infile, 0, SEEK_END);
  834. long Size = ftell(infile);
  835. rewind(infile);
  836.  
  837. size_t result = sizeof(*temp);
  838.  
  839.  
  840. */
  841.  
  842.  
  843. /* strcpy(pp->name, "fafwe");
  844. strcpy(pp->number, "1234");
  845. printf_s("%s", (*pp).name);
  846. //printf("%s", *pp.number);
  847. FILE *outfile;
  848. outfile = fopen("acc.dat", "w");
  849. if (outfile == NULL)
  850. {
  851. fprintf(stderr, "\nError opening accounts.dat\n\n");
  852. exit(1);
  853. }
  854. // instructions to user
  855. printf("Enter \"stop\" for First Name to end program.");
  856. // endlessly read from keyboard and write to file
  857. fwrite(&pp, sizeof(struct Item), 1, outfile);
  858. fclose(outfile);*/
  859.  
  860. /*FILE *infile;
  861.  
  862. infile = fopen("acc.dat", "r");
  863. if (infile == NULL)
  864. {
  865. fprintf(stderr, "\nError opening accounts.dat\n\n");
  866. exit(1);
  867. }
  868. fread(pp, sizeof(struct Item*), 1, infile);
  869. printf("Name = %s %s ", pp->name, pp->number);*/
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880. /*#include <stdio.h>
  881. #include <stdlib.h>
  882. #include <string.h>
  883. #include <conio.h>
  884. #pragma warning(disable : 4996)
  885. // a structure to read and write
  886. struct customer {
  887. char fname[20], lname[20];
  888. int acct_num;
  889. float acct_balance;
  890. };
  891. typedef struct Item
  892. {
  893. struct Item *next;
  894. char* name;
  895. char* number;
  896. } Item;
  897.  
  898.  
  899. void main()
  900. {
  901. FILE *outfile;
  902. FILE *infile;
  903. struct customer input;
  904. outfile = fopen("accounts.dat", "w");
  905. if (outfile == NULL)
  906. {
  907. fprintf(stderr, "\nError opening accounts.dat\n\n");
  908. exit(1);
  909. }
  910.  
  911. // instructions to user
  912. printf("Enter \"stop\" for First Name to end program.");
  913.  
  914. // endlessly read from keyboard and write to file
  915. while (1)
  916. {
  917. // prompt user
  918. printf("\nFirst Name: ");
  919. scanf("%s", input.fname);
  920. // exit if no name provided
  921. if (strcmp(input.fname, "stop") == 0)
  922. goto r;
  923. // continue reading from keyboard
  924. printf("Last Name : ");
  925. scanf("%s", input.lname);
  926. printf("Acct Num : ");
  927. scanf("%d", &input.acct_num);
  928. printf("Balance : ");
  929. scanf("%f", &input.acct_balance);
  930.  
  931. // write entire structure to Accounts file
  932. fwrite(&input, sizeof(struct customer), 1, outfile);
  933. }
  934. r:
  935. fclose(outfile);
  936.  
  937. infile = fopen("accounts.dat", "r");
  938. if (infile == NULL)
  939. {
  940. fprintf(stderr, "\nError opening accounts.dat\n\n");
  941. exit(1);
  942. }
  943.  
  944. while (fread(&input, sizeof(struct customer), 1, infile))
  945. printf("Name = %10s %10s Acct Num = %8d Balance = %8.2f\n",
  946. input.fname, input.lname, input.acct_num, input.acct_balance);
  947. _getch();
  948.  
  949.  
  950. } */
  951.  
  952. /*
  953. 2napravlen
  954.  
  955. if (&(*node)->next == NULL)
  956. {
  957. temp->next = NULL;
  958. //temp->next = &(*node)->next;
  959. (**node).next = temp;
  960. temp->prev = &(*node);
  961. }
  962.  
  963. else
  964. {
  965. temp->next = &(*node)->next;
  966. (*node)->next->prev = &temp;
  967. (*node)->next = &temp;
  968. temp->prev = &(*node);
  969. }
  970.  
  971. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement