Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include <stdbool.h>
- #include <locale.h>
- #pragma warning(disable : 4996)
- static bool parse(char s[], int r)
- {
- int i;
- if (!s)
- return false;
- for (i = 0; i < r - 1; i++)
- {
- if (s[i] != '0' && s[i] != '1' &&
- s[i] != '2' && s[i] != '3' &&
- s[i] != '4' && s[i] != '5' &&
- s[i] != '6' && s[i] != '7' &&
- s[i] != '8' && s[i] != '9') {
- return false;
- }
- if (s[0] == ' ')
- {
- return false;
- }
- }
- return true;
- }
- static bool parse1(char s[], int r)
- {
- int i;
- if (!s)
- return false;
- for (i = 0; i < r - 1; i++)
- {
- if (s[i] != '0' && s[i] != '1' &&
- s[i] != '2' && s[i] != '3' &&
- s[i] != '4' && s[i] != '5' &&
- s[i] != '6' && s[i] != '7' &&
- s[i] != '8' && s[i] != '9' && s[i] != '-') {
- return false;
- }
- if (s[i + 1] == '-')
- return false;
- if (s[i] == ' ')
- {
- return false;
- }
- }
- return true;
- }
- typedef char tName[30];
- typedef char tBirthday[30];
- typedef char tNumber[30];
- typedef char tSex[30];
- typedef char tSpecial[30];
- typedef char tEducation[30];
- typedef char tContact[30];
- typedef char tCity[30];
- typedef char tEmployment[30];
- typedef char tSalary[30];
- typedef char tCompany[30];
- typedef char tPost[30];
- typedef char tStatus[30];
- typedef char tAge[30];
- typedef struct Vacancy
- {
- struct Vacancy* next, *prev;
- tCompany company;
- tCity city;
- tPost post;
- tSpecial special;
- tAge age;
- tEducation education;
- tSex sex;
- tSalary salary;
- } Vacancy;
- typedef struct Bidder
- {
- struct Bidder* next, *prev;
- tName name;
- tBirthday birthday;
- tContact contact;
- tSex sex;
- tSpecial special;
- tEducation education;
- tCity city;
- tSalary salary;
- } Bidder;
- static void menu();
- void DelNode(Vacancy** Dnode, int count, int Compare);
- void DelNodeBidder(Bidder** Dnode, int count, int Compare);
- int CheckDigit();
- char* CheckLetter(char* name);
- void AddNode(Vacancy** head);
- void print(Vacancy *node);
- void save(Vacancy* pp, Bidder* pp2);
- void load(Vacancy** pp2, Bidder** pp);
- void Add(char* company, char* city, char* post, char* special, char* education, char* sex, char* age, char* salary, Vacancy **node);
- int Search(char* name, Vacancy* node, int N);
- int SearchBidder(char* name, Bidder* node, int N);
- static void menuSearchVacancy();
- static void menuSearchBidder();
- void destroylist(Vacancy** n);
- void destroylistBidder(Bidder** n);
- void printBidder(Bidder* node);
- void AddNodeBidder(Bidder** head);
- void AddBidder(char* name, char* birthday, char* contact, char* sex, char* special, char* education, char* city, char* salary, Bidder **node);
- int Count(Vacancy* node, int i);
- int main()
- {
- int choise;
- int Srch = 0;
- char n[256];
- setlocale(LC_ALL, "rus");
- char name[256];
- Vacancy* BufferList = NULL;
- Bidder* BufferBidder = NULL;
- start:
- menu();
- if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) <4)
- printf("%s", "ok\n");
- else
- {
- (void)puts("ERROR");
- destroylist(&BufferList);
- destroylistBidder(&BufferBidder);
- return 0;
- }
- switch (atoi(n))
- {
- case 1:
- print(BufferList);
- puts("Продолжить?");
- puts("1. Да ");
- puts("2. Нет ");
- if (CheckDigit() == 1)
- goto start;
- else
- break;
- case 2:
- AddNode(&BufferList);
- goto start;
- case 3:
- save(BufferList, BufferBidder);
- destroylist(&BufferList);
- destroylistBidder(&BufferBidder);
- goto start;
- case 4:
- destroylist(&BufferList);
- load(&BufferList, &BufferBidder);
- goto start;
- case 5:
- menuSearchVacancy();
- choise = CheckDigit();
- CheckLetter(name);
- Srch = Search(name, BufferList, choise);
- if (Srch > 0)
- DelNode(&BufferList, Srch - 1, 0);
- goto start;
- case 6:
- printBidder(BufferBidder);
- puts("Продолжить?");
- puts("1. Да ");
- puts("2. нет ");
- if (CheckDigit() == 1)
- goto start;
- else
- break;
- case 7:
- AddNodeBidder(&BufferBidder);
- goto start;
- case 8:
- menuSearchBidder();
- choise = CheckDigit();
- CheckLetter(name);
- Srch = SearchBidder(name, BufferBidder, choise);
- if (Srch > 0)
- DelNodeBidder(&BufferBidder, Srch - 1, 0);
- goto start;
- }
- destroylist(&BufferList);
- destroylistBidder(&BufferBidder);
- return 0;
- }
- int Search(char* name, Vacancy* node, int N)
- {
- int i, k, Check;
- int con = 0;
- char temp[256];
- puts("search");
- while (node != NULL)
- {
- switch (N)
- {
- case 1:
- strcpy(temp, node->company);
- break;
- case 2:
- strcpy(temp, node->city);
- break;
- case 3:
- strcpy(temp, node->post);
- break;
- case 4:
- strcpy(temp, node->special);
- break;
- case 5:
- strcpy(temp, node->education);
- break;
- case 6:
- strcpy(temp, node->sex);
- break;
- case 7:
- strcpy(temp, node->age);
- break;
- case 8:
- strcpy(temp, node->salary);
- break;
- default:
- puts("Ошибка ввода");
- }
- con++;
- k = 0;
- Check = 0;
- for (i = 0; i < strlen(name);i++)
- {
- if (name[i] == temp[i])
- {
- k++;
- }
- if (k == strlen(name))
- if (k == strlen(temp))
- {
- printf("Название компании - %s\r", node->company);
- printf("Город - %s\r", node->city);
- printf("Должность - %s\r", node->post);
- printf("Специальность - %s\r", node->special);
- printf("Образование - %s\r", node->education);
- printf("Пол - %s\r", node->sex);
- printf("Возраст - %s\r", node->age);
- printf("Уровень оплаты - %s\r", node->salary);
- puts("\n");
- puts("1.Продолжить поиск");
- puts("2.Удалить ");
- puts("3.Меню ");
- Check = CheckDigit();
- if (Check == 3)
- goto done;
- if (Check == 2)
- {
- return con;
- }
- if (Check == 1)
- {
- }
- }
- }
- node = node->next;
- }
- done:
- {
- return 0;
- }
- }
- int SearchBidder(char* name, Bidder* node, int N)
- {
- int i, k, Check;
- int con = 0;
- char temp[256];
- puts("search");
- while (node != NULL)
- {
- switch (N)
- {
- case 1:
- strcpy(temp, node->name);
- break;
- case 2:
- strcpy(temp, node->birthday);
- break;
- case 3:
- strcpy(temp, node->contact);
- break;
- case 4:
- strcpy(temp, node->sex);
- break;
- case 5:
- strcpy(temp, node->special);
- break;
- case 6:
- strcpy(temp, node->education);
- break;
- case 7:
- strcpy(temp, node->city);
- break;
- case 8:
- strcpy(temp, node->salary);
- break;
- default:
- puts("Ошибка ввода");
- }
- con++;
- k = 0;
- Check = 0;
- for (i = 0; i < strlen(name);i++)
- {
- if (name[i] == temp[i])
- {
- k++;
- }
- if (k == strlen(name))
- if (k == strlen(temp))
- {
- printf("Имя - %s\r", node->name);
- printf("Год рождения - %s\r", node->birthday);
- printf("Контакты - %s\r", node->contact);
- printf("Пол - %s\r", node->sex);
- printf("Специальность - %s\r", node->special);
- printf("Образование - %s\r", node->education);
- printf("город - %s\r", node->city);
- printf("Уровень оплаты - %s\r", node->salary);
- puts("\n");
- puts("1.Продолжить поиск");
- puts("2.Удалить ");
- puts("3.Меню ");
- Check = CheckDigit();
- if (Check == 3)
- goto done;
- if (Check == 2)
- {
- return con;
- }
- if (Check == 1)
- {
- }
- }
- }
- node = node->next;
- }
- done:
- {
- return 0;
- }
- }
- void DelNode(Vacancy** Dnode, int count, int Compare)
- {
- if (Compare == count)
- {
- Vacancy *tmp = NULL;
- tmp = (*Dnode);
- (*Dnode) = (*Dnode)->next;
- free(tmp);
- goto rr;
- }
- else
- {
- DelNode((Vacancy**)(*Dnode), count, Compare + 1);
- }
- rr: {}
- }
- void DelNodeBidder(Bidder** Dnode, int count, int Compare)
- {
- if (Compare == count)
- {
- Bidder *tmp = NULL;
- tmp = (*Dnode);
- (*Dnode) = (*Dnode)->next;
- free(tmp);
- goto rr;
- }
- else
- {
- DelNodeBidder((Bidder**)(*Dnode), count, Compare + 1);
- }
- rr: {}
- }
- void AddBidder(char* name, char* birthday, char* contact, char* sex, char* special, char* education, char* city, char* salary, Bidder **node)
- {
- Bidder *temp = (Bidder*)malloc(sizeof(Bidder));
- memset(temp, 0, sizeof(*temp));
- if (!(temp))
- {
- free(temp);
- (void)puts("ERROR MEMORY");
- exit(0);
- }
- strcpy(temp->name, name);
- strcpy(temp->birthday, birthday);
- strcpy(temp->contact, contact);
- strcpy(temp->sex, sex);
- strcpy(temp->special, special);
- strcpy(temp->education, education);
- strcpy(temp->city, city);
- strcpy(temp->salary, salary);
- temp->next = **&node;
- *node = temp;
- }
- void Add(char* company, char* city, char* post, char* special, char* education, char* sex, char* age, char* salary, Vacancy **node)
- {
- Vacancy *temp = (Vacancy *)malloc(sizeof(Vacancy));
- memset(temp, 0, sizeof(*temp));
- if (!(temp))
- {
- free(temp);
- (void)puts("ERROR MEMORY");
- exit(0);
- }
- strcpy(temp->company, company);
- strcpy(temp->city, city);
- strcpy(temp->post, post);
- strcpy(temp->special, special);
- strcpy(temp->education, education);
- strcpy(temp->sex, sex);
- strcpy(temp->age, age);
- strcpy(temp->salary, salary);
- temp->next = **&node;
- *node = temp;
- }
- void save(Vacancy* pp, Bidder* pp2)
- {
- FILE *outfile;
- FILE *outfile2;
- outfile = fopen("acc.dat", "w+");
- if (outfile == NULL)
- {
- fprintf(stderr, "\nError opening acc.dat\n\n");
- exit(1);
- }
- while (pp != NULL)
- {
- fwrite(pp, sizeof(struct Vacancy), 1, outfile);
- pp = pp->next;
- }
- fclose(outfile);
- outfile2 = fopen("acc2.dat", "w+");
- while (pp2 != NULL)
- {
- fwrite(pp2, sizeof(struct Bidder), 1, outfile2);
- pp2 = pp2->next;
- }
- fclose(outfile2);
- }
- void load(Vacancy** pp2, Bidder** pp)
- {
- FILE* infile;
- FILE* infile2;
- infile = fopen("acc.dat", "a+");
- if (infile == NULL)
- {
- fprintf(stderr, "\nError opening acc.dat\n\n");
- exit(1);
- }
- while (!feof(infile))
- {
- Vacancy *temp = (Vacancy *)malloc(sizeof(Vacancy));
- memset(temp, 0, sizeof(*temp));
- fread(temp, sizeof(struct Vacancy), 1, infile);
- if (strlen(temp->company) != 0)
- Add(temp->company, temp->city, temp->post, temp->special, temp->education, temp->sex, temp->age, temp->salary, pp2);
- free(temp);
- }
- fclose(infile);
- infile2 = fopen("acc2.dat", "a+");
- if (infile2 == NULL)
- {
- fprintf(stderr, "\nError opening acc.dat\n\n");
- exit(1);
- }
- while (!feof(infile2))
- {
- Bidder *temp = (Bidder *)malloc(sizeof(Bidder));
- memset(temp, 0, sizeof(*temp));
- fread(temp, sizeof(struct Bidder), 1, infile2);
- if (strlen(temp->name) != 0)
- AddBidder(temp->name, temp->birthday, temp->contact, temp->sex, temp->special, temp->education, temp->city, temp->salary, pp);
- free(temp);
- }
- fclose(infile2);
- }
- void print(Vacancy *node)
- {
- puts("Вакансии ");
- while (node != NULL)
- {
- printf("Название компании - %s\r", node->company);
- printf("Город - %s\r", node->city);
- printf("Должность - %s\r", node->post);
- printf("Специальность - %s\r", node->special);
- printf("Образование - %s\r", node->education);
- printf("Пол - %s\r", node->sex);
- printf("Возраст - %s\r", node->age);
- printf("Уровень оплаты - %s\r", node->salary);
- puts("\n");
- node = node->next;
- }
- puts("\n");
- }
- void printBidder(Bidder* node)
- {
- puts("Претенденты ");
- while (node != NULL)
- {
- printf("Имя - %s\r", node->name);
- printf("Год рождения - %s\r", node->birthday);
- printf("Контакты - %s\r", node->contact);
- printf("Пол - %s\r", node->sex);
- printf("Специальность - %s\r", node->special);
- printf("Образование - %s\r", node->education);
- printf("город - %s\r", node->city);
- printf("Уровень оплаты - %s\r", node->salary);
- puts("\n");
- node = node->next;
- }
- puts("\n");
- }
- int Count(Vacancy* node, int i)
- {
- puts("count ");
- while (node != NULL)
- {
- i++;
- node = (Vacancy*)node->next;
- }
- return i;
- }
- void AddNode(Vacancy** head)
- {
- int i;
- char n[256];
- char entry1[256];
- char entry2[256];
- char entry3[256];
- char entry4[256];
- char entry5[256];
- char entry6[256];
- char entry7[256];
- char entry8[256];
- puts("HOW MUCH?");
- if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) < 4)
- printf("%s", "\n");
- else
- {
- (void)puts("ERROR");
- exit(1);
- }
- if (atoi(n) != 0)
- for (i = 0; i < atoi(n);i++)
- {
- puts("Введите Название компании");
- if (fgets(entry1, 15, stdin) != NULL)
- {
- puts("Введите Город");
- if (fgets(entry2, 15, stdin) != NULL)
- {
- puts("Введите Должность");
- if (fgets(entry3, 15, stdin) != NULL)
- {
- puts("Введите Специальность");
- if (fgets(entry4, 15, stdin) != NULL)
- {
- puts("Введите Образование");
- if (fgets(entry5, 15, stdin) != NULL)
- {
- puts("Введите Пол");
- if (fgets(entry6, 15, stdin) != NULL)
- {
- puts("Введите Возраст");
- if (fgets(entry7, 15, stdin) != NULL)
- {
- puts("Введите Уровень оплаты");
- if (fgets(entry8, 15, stdin) != NULL)
- {
- Add(entry1, entry2, entry3, entry4, entry5, entry6, entry7, entry8, head);
- }
- else
- {
- (void)puts("ERROR");
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- else
- {
- destroylist(head);
- }
- }
- }
- void AddNodeBidder(Bidder** head)
- {
- int i;
- char n[256];
- char entry1[256];
- char entry2[256];
- char entry3[256];
- char entry4[256];
- char entry5[256];
- char entry6[256];
- char entry7[256];
- char entry8[256];
- puts("HOW MUCH?");
- if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) <4)
- printf("%s", "\n");
- else
- {
- (void)puts("ERROR");
- exit(1);
- }
- if (atoi(n) != 0)
- for (i = 0; i < atoi(n);i++)
- {
- puts("Введите Имя ");
- if (fgets(entry1, 15, stdin) != NULL)
- {
- puts("Введите Год рождения");
- if (fgets(entry2, 15, stdin) != NULL)
- {
- puts("Введите Контакты");
- if (fgets(entry3, 15, stdin) != NULL)
- {
- puts("Введите Пол ");
- if (fgets(entry4, 15, stdin) != NULL)
- {
- puts("Введите Специальность ");
- if (fgets(entry5, 15, stdin) != NULL)
- {
- puts("Введите Образование");
- if (fgets(entry6, 15, stdin) != NULL)
- {
- puts("Введите город ");
- if (fgets(entry7, 15, stdin) != NULL)
- {
- puts("Введите Уровень оплаты");
- if (fgets(entry8, 15, stdin) != NULL)
- {
- AddBidder(entry1, entry2, entry3, entry4, entry5, entry6, entry7, entry8, head);
- }
- else
- {
- (void)puts("ERROR");
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- else
- {
- destroylistBidder(head);
- }
- }
- }
- static void menu()
- {
- (void)puts("\n********************************************************\n");
- (void)puts(" 1. Просмотр списка Вакансий \n");
- (void)puts(" 2. Добавить в список Вакансий \n");
- (void)puts(" 3. Сохранить в файл \n");
- (void)puts(" 4. Загрузить из файла \n");
- (void)puts(" 5. Поиск по вакансиям \n");
- (void)puts(" 6. Просмотр списка Претендентов \n");
- (void)puts(" 7. Добавить в список Претендентов \n");
- (void)puts(" 8. Поиск по претендентам \n");
- (void)puts(" 9. Exit \n");
- (void)puts("**********************************************************\n");
- }
- static void menuSearchBidder()
- {
- (void)puts("\n********************************************************\n");
- (void)puts(" 1. Поиск по имени \n");
- (void)puts(" 2. Поиск по году рождения \n");
- (void)puts(" 3. Поиск по контактам \n");
- (void)puts(" 4. Поиск по полу \n");
- (void)puts(" 5. Поиск по Специальности \n");
- (void)puts(" 6. Поиск по Образованию \n");
- (void)puts(" 7. Поиск по городу \n");
- (void)puts(" 8. Поиск по Уровеню оплаты \n");
- (void)puts(" 9. return. \n");
- (void)puts("**********************************************************\n");
- }
- static void menuSearchVacancy()
- {
- (void)puts("\n********************************************************\n");
- (void)puts(" 1. Поиск по названию компании \n");
- (void)puts(" 2. Поиск по городу \n");
- (void)puts(" 3. Поиск по должности \n");
- (void)puts(" 4. Поиск по специальности \n");
- (void)puts(" 5. Поиск по образованию \n");
- (void)puts(" 6. Поиск по полу \n");
- (void)puts(" 7. Поиск по возрасту \n");
- (void)puts(" 8. Поиск по зарплате в $ \n");
- (void)puts(" 9. return. \n");
- (void)puts("**********************************************************\n");
- }
- int CheckDigit()
- {
- char n[256];
- if (fgets(n, 15, stdin) != NULL && parse(n, (int)strlen(n)) == true && strlen(n) <4)
- printf("%s", "ok\n");
- else
- {
- (void)puts("ERROR");
- return 0;
- }
- return atoi(n);
- }
- char* CheckLetter(char* name)
- {
- char n[256];
- if (fgets(n, 24, stdin) != NULL && strlen(n) <40)
- printf("%s", "ok\n");
- else
- {
- (void)puts("ERROR");
- return 0;
- }
- strcpy(name, n);
- return (name);
- }
- void destroylist(Vacancy** n)
- {
- if (!*n) return;
- destroylist(&((*n)->next));
- free(*n);
- *n = NULL;
- }
- void destroylistBidder(Bidder** n)
- {
- if (!*n) return;
- destroylistBidder(&((*n)->next));
- free(*n);
- *n = NULL;
- }
- /* razmer
- setlocale(LC_ALL, "rus");
- fseek(infile, 0, SEEK_END);
- long Size = ftell(infile);
- rewind(infile);
- size_t result = sizeof(*temp);
- */
- /* strcpy(pp->name, "fafwe");
- strcpy(pp->number, "1234");
- printf_s("%s", (*pp).name);
- //printf("%s", *pp.number);
- FILE *outfile;
- outfile = fopen("acc.dat", "w");
- if (outfile == NULL)
- {
- fprintf(stderr, "\nError opening accounts.dat\n\n");
- exit(1);
- }
- // instructions to user
- printf("Enter \"stop\" for First Name to end program.");
- // endlessly read from keyboard and write to file
- fwrite(&pp, sizeof(struct Item), 1, outfile);
- fclose(outfile);*/
- /*FILE *infile;
- infile = fopen("acc.dat", "r");
- if (infile == NULL)
- {
- fprintf(stderr, "\nError opening accounts.dat\n\n");
- exit(1);
- }
- fread(pp, sizeof(struct Item*), 1, infile);
- printf("Name = %s %s ", pp->name, pp->number);*/
- /*#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #pragma warning(disable : 4996)
- // a structure to read and write
- struct customer {
- char fname[20], lname[20];
- int acct_num;
- float acct_balance;
- };
- typedef struct Item
- {
- struct Item *next;
- char* name;
- char* number;
- } Item;
- void main()
- {
- FILE *outfile;
- FILE *infile;
- struct customer input;
- outfile = fopen("accounts.dat", "w");
- if (outfile == NULL)
- {
- fprintf(stderr, "\nError opening accounts.dat\n\n");
- exit(1);
- }
- // instructions to user
- printf("Enter \"stop\" for First Name to end program.");
- // endlessly read from keyboard and write to file
- while (1)
- {
- // prompt user
- printf("\nFirst Name: ");
- scanf("%s", input.fname);
- // exit if no name provided
- if (strcmp(input.fname, "stop") == 0)
- goto r;
- // continue reading from keyboard
- printf("Last Name : ");
- scanf("%s", input.lname);
- printf("Acct Num : ");
- scanf("%d", &input.acct_num);
- printf("Balance : ");
- scanf("%f", &input.acct_balance);
- // write entire structure to Accounts file
- fwrite(&input, sizeof(struct customer), 1, outfile);
- }
- r:
- fclose(outfile);
- infile = fopen("accounts.dat", "r");
- if (infile == NULL)
- {
- fprintf(stderr, "\nError opening accounts.dat\n\n");
- exit(1);
- }
- while (fread(&input, sizeof(struct customer), 1, infile))
- printf("Name = %10s %10s Acct Num = %8d Balance = %8.2f\n",
- input.fname, input.lname, input.acct_num, input.acct_balance);
- _getch();
- } */
- /*
- 2napravlen
- if (&(*node)->next == NULL)
- {
- temp->next = NULL;
- //temp->next = &(*node)->next;
- (**node).next = temp;
- temp->prev = &(*node);
- }
- else
- {
- temp->next = &(*node)->next;
- (*node)->next->prev = &temp;
- (*node)->next = &temp;
- temp->prev = &(*node);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement